Skip to content

Add the ability to add custom classes to api-method sidebar items #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,26 @@ 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(
{
"menu__list-item--deprecated": item.api.deprecated,
"api-method": !!item.api.method,
},
classNameConfig,
item.api.method
)
: clsx(
Expand Down
Loading