diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts index c7ffccc0f..c7ebe16aa 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts @@ -38,7 +38,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 1fb5d8a05..1c9539170 100644 --- a/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts +++ b/packages/docusaurus-theme-openapi-docs/src/markdown/utils.ts @@ -26,11 +26,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.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.tsx index 837d0ba38..1763c4220 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.tsx +++ b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.tsx @@ -10,6 +10,19 @@ import React from "react"; 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 { + getQualifierMessage, + getSchemaName, +} from "docusaurus-theme-openapi-docs/lib/markdown/schema"; +/* eslint-disable import/no-extraneous-dependencies*/ +import { + guard, + toString, +} from "docusaurus-theme-openapi-docs/lib/markdown/utils"; import ReactMarkdown from "react-markdown"; import rehypeRaw from "rehype-raw"; @@ -40,7 +53,7 @@ export interface Props { } function ParamsItem({ - param: { description, example, examples, name, required, schema }, + param: { description, example, examples, name, required, schema, deprecated }, }: Props) { if (!schema || !schema?.type) { schema = { type: "any" }; @@ -54,6 +67,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.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx index b444e1dc1..233c6d3b7 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx +++ b/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx @@ -111,7 +111,7 @@ export default function SchemaItem({ )} {renderNullable} - {!deprecated && renderRequired} + {renderRequired} {renderDeprecated} {renderQualifierMessage}