PaloAltoNetworks / docusaurus-openapi-docs

🦝 OpenAPI plugin for generating API reference docs in Docusaurus v3.
https://docusaurus-openapi.tryingpan.dev
MIT License
723 stars 239 forks source link

Add classes to sidebar items when certain API specification criteria are met. #858

Closed tyler-mairose-sp closed 2 months ago

tyler-mairose-sp commented 4 months ago

Is your feature request related to a problem?

No

Describe the solution you'd like

I am looking for a way to re-create the same functionality that you have for the item.api.deprecated field for another field experimental.

I see that when the sidebar.js is generated a check for the deprecated: true field happens here:

"menu__list-item--deprecated": item.api.deprecated,

  function createDocItem(
    item: ApiPageMetadata | SchemaPageMetadata
  ): SidebarItemDoc {
    const sidebar_label = item.frontMatter.sidebar_label;
    const title = item.title;
    const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
    const className =
      item.type === "api"
        ? clsx(
            {
              "menu__list-item--deprecated": item.api.deprecated,
              "api-method": !!item.api.method,
            },
            item.api.method
          )
        : clsx({
            "menu__list-item--deprecated": item.schema.deprecated,
          });
    return {
      type: "doc" as const,
      id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
      label: (sidebar_label as string) ?? title ?? id,
      customProps: customProps,
      className: className ? className : undefined,
    };

Is it possible to overwrite this function to add something like "menu__list-item--experimental": item.api.experimental,?

Describe alternatives you've considered

I've considered writing a script to update the sidebar.js after it is generated but that seems like not a good long term solution.

I can also just clone your package and make the updates (This is what I did to test and make sure it works to add the experimental class to the sidebar items.) Again, not a good option because we would diverge from your code and not get any updates when we would want upgrade your package.

Additional context

tyler-mairose-sp commented 4 months ago

@sserrata Would you have any suggestions for this?