From e785058a82a7d484b8ad33c4964c0d565b20c4b6 Mon Sep 17 00:00:00 2001 From: Steven Serrata <9343811+sserrata@users.noreply.github.com> Date: Fri, 24 Jan 2025 10:32:41 -0500 Subject: [PATCH] add support for json schema null type (#1068) --- demo/examples/petstore-3.1.yaml | 4 +++- .../src/theme/SchemaItem/index.tsx | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/demo/examples/petstore-3.1.yaml b/demo/examples/petstore-3.1.yaml index ab1322af6..693798248 100644 --- a/demo/examples/petstore-3.1.yaml +++ b/demo/examples/petstore-3.1.yaml @@ -1077,7 +1077,9 @@ components: - $ref: "#/components/schemas/Category" name: description: The name given to a pet - type: string + type: + - string + - "null" example: Guru photoUrls: description: The list of URL to a cute photos featuring pet 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 65984c318..fa2091e32 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx +++ b/packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx @@ -72,9 +72,13 @@ export default function SchemaItem(props: Props) { enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]); defaultValue = schema.default; example = schema.example; - nullable = schema.nullable; + nullable = + schema.nullable || + (Array.isArray(schema.type) && schema.type.includes("null")); // support JSON Schema nullable } + console.log(schema); + const renderRequired = guard( Array.isArray(required) ? required.includes(name) : required, () => required