diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts index bc8b209a8..cb84b8298 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts @@ -24,7 +24,7 @@ export function guard( value: T | undefined, cb: (value: T) => Children ): string { - if (!!value) { + if (!!value || value === 0) { const children = cb(value); return render(children); } diff --git a/packages/docusaurus-theme-openapi-docs/src/markdown/utils.test.ts b/packages/docusaurus-theme-openapi-docs/src/markdown/utils.test.ts index 108a82705..999b929db 100644 --- a/packages/docusaurus-theme-openapi-docs/src/markdown/utils.test.ts +++ b/packages/docusaurus-theme-openapi-docs/src/markdown/utils.test.ts @@ -22,6 +22,11 @@ describe("guard", () => { expect(actual).toBe(""); }); + it("should guard false booleans", () => { + const actual = guard(false, (value) => `${value}`); + expect(actual).toBe(""); + }); + it("should not guard strings", () => { const actual = guard("hello", (value) => value); expect(actual).toBe("hello"); @@ -37,10 +42,6 @@ describe("guard", () => { expect(actual).toBe("0"); }); - it("should not guard false booleans", () => { - const actual = guard(false, (value) => `${value}`); - expect(actual).toBe("false"); - }); it("should not guard true booleans", () => { const actual = guard(true, (value) => `${value}`); expect(actual).toBe("true"); diff --git a/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts b/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts index 5b02a8079..7221cb92c 100644 --- a/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts +++ b/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts @@ -24,11 +24,11 @@ export function guard( value: T | undefined | string, cb: (value: T) => Children ): string { - if (value === undefined || value === "") { - return ""; + if (!!value || value === 0) { + const children = cb(value as T); + return render(children); } - const children = cb(value as T); - return render(children); + return ""; } export function render(children: Children): string { diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.js b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.js index 1e2a40f12..9954cc9da 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.js +++ b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.js @@ -11,6 +11,7 @@ import CodeBlock from "@theme/CodeBlock"; import SchemaTabs from "@theme/SchemaTabs"; import TabItem from "@theme/TabItem"; /* eslint-disable import/no-extraneous-dependencies*/ +import clsx from "clsx"; import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription"; /* eslint-disable import/no-extraneous-dependencies*/ import { @@ -26,8 +27,10 @@ import ReactMarkdown from "react-markdown"; import rehypeRaw from "rehype-raw"; function ParamsItem({ - param: { description, example, examples, name, required, schema }, + param: { description, example, examples, name, required, schema, deprecated }, }) { + console.log(name, required); + if (!schema || !schema?.type) { schema = { type: "any" }; } @@ -40,6 +43,10 @@ function ParamsItem({ required )); + const renderDeprecated = guard(deprecated, () => ( + deprecated + )); + const renderSchema = guard(getQualifierMessage(schema), (message) => (
- {name} + + {name} + {renderSchemaName} - {required && } + {(required || deprecated) && ( + + )} {renderSchemaRequired} + {renderDeprecated} {renderSchema} {renderDefaultValue} diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.js b/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.js index d53aea2cc..952b4e2bd 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.js +++ b/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.js @@ -100,7 +100,7 @@ function SchemaItem({ )} {renderNullable} - {!deprecated && renderRequired} + {renderRequired} {renderDeprecated} {renderQualifierMessage}