From ff6d06384b0c4ff378150a28e7f23484e4274b3c Mon Sep 17 00:00:00 2001 From: Tyler Mairose Date: Sun, 21 Jul 2024 17:31:16 -0400 Subject: [PATCH] Add the ability to add custom classes to api-method sidebar items --- .../src/sidebars/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts b/packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts index def167105..324b10710 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts @@ -107,6 +107,18 @@ function groupByTags( const sidebar_label = item.frontMatter.sidebar_label; const title = item.title; const id = item.type === "schema" ? `schemas/${item.id}` : item.id; + interface classChecks { + [key: string]: string; + } + + let classNameConfig: classChecks = {} + + if(customProps !== undefined) { + for (const [key, value] of Object.entries(customProps['additionalClassChecks'] as Object)) { + classNameConfig[key] = new Function('item', `return ${value}`)(item) as string; // Type assertion for the return value + } + } + const className = item.type === "api" ? clsx( @@ -114,6 +126,7 @@ function groupByTags( "menu__list-item--deprecated": item.api.deprecated, "api-method": !!item.api.method, }, + classNameConfig, item.api.method ) : clsx(