docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

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

Open tyler-mairose-sp opened this issue 1 year ago • 0 comments

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

  • Version used:
  • Docusaurus Version: 2.4.3
  • docusaurus-theme-openapi-docs version: 2.0.2
  • Environment name and version (e.g. Chrome 59, node.js 5.4, python 3.7.3): Chrome Version 124.0.6367.203
  • Operating System and version (desktop or mobile): MacOS 14.5 (23F79)
  • Link to your project: https://github.com/sailpoint-oss/developer.sailpoint.com

tyler-mairose-sp avatar Jul 01 '24 13:07 tyler-mairose-sp