Skip to content

fix(plugin): render OpenAPI 3.1 type unions in schema names (#950)#1475

Open
sserrata wants to merge 1 commit into
mainfrom
fix/openapi-31-type-arrays-950
Open

fix(plugin): render OpenAPI 3.1 type unions in schema names (#950)#1475
sserrata wants to merge 1 commit into
mainfrom
fix/openapi-31-type-arrays-950

Conversation

@sserrata
Copy link
Copy Markdown
Member

Summary

What changed

  • Normalize array-form type in prettyName/getSchemaName and join with " | ".
  • Single-element arrays (["integer"]) unwrap to the bare type.
  • Format and title rendering both handle the union case.
  • Added 4 unit tests covering union, single-element, format, and array-of-union.

Test plan

  • npx jest packages/docusaurus-plugin-openapi-docs/src/markdown/schema.test.ts — 9/9 pass
  • Existing createSchema and sidebars suites still pass
  • Reviewer to spot-check rendering on a 3.1 spec with nullable type arrays

Note: still does not yet cover anyOf/allOf/oneOf member type unions (per @robbieaverill's follow-up on #950). Happy to handle in a follow-up PR if reviewers prefer to keep this scoped.

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Size Change: 0 B

Total Size: 2.32 MB

ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 16.4 kB
demo/.docusaurus/globalData.json 76.2 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/registry.js 110 kB
demo/.docusaurus/routes.js 104 kB
demo/.docusaurus/routesChunkNames.json 43.3 kB
demo/.docusaurus/site-metadata.json 1.58 kB
demo/build/assets/css/styles.********.css 173 kB
demo/build/assets/js/main.********.js 682 kB
demo/build/assets/js/runtime~main.********.js 25.1 kB
demo/build/index.html 99.5 kB
demo/build/petstore/add-pet/index.html 30 kB
demo/build/petstore/create-user/index.html 24.7 kB
demo/build/petstore/create-users-with-array-input/index.html 24.8 kB
demo/build/petstore/create-users-with-list-input/index.html 24.8 kB
demo/build/petstore/delete-order/index.html 24.5 kB
demo/build/petstore/delete-pet/index.html 24.8 kB
demo/build/petstore/delete-user/index.html 25 kB
demo/build/petstore/find-pets-by-status/index.html 25.5 kB
demo/build/petstore/find-pets-by-tags/index.html 26.2 kB
demo/build/petstore/get-inventory/index.html 23.8 kB
demo/build/petstore/get-order-by-id/index.html 24.8 kB
demo/build/petstore/get-pet-by-id/index.html 25.6 kB
demo/build/petstore/get-user-by-name/index.html 25.1 kB
demo/build/petstore/login-user/index.html 25.6 kB
demo/build/petstore/logout-user/index.html 24.4 kB
demo/build/petstore/new-pet/index.html 25 kB
demo/build/petstore/pet/index.html 23.2 kB
demo/build/petstore/place-order/index.html 24 kB
demo/build/petstore/schemas/apiresponse/index.html 25.2 kB
demo/build/petstore/schemas/cat/index.html 39.1 kB
demo/build/petstore/schemas/category/index.html 26.3 kB
demo/build/petstore/schemas/dog/index.html 39.3 kB
demo/build/petstore/schemas/honeybee/index.html 39.3 kB
demo/build/petstore/schemas/id/index.html 23.4 kB
demo/build/petstore/schemas/order/index.html 27.3 kB
demo/build/petstore/schemas/pet/index.html 38.8 kB
demo/build/petstore/schemas/tag/index.html 24.7 kB
demo/build/petstore/schemas/user/index.html 40.7 kB
demo/build/petstore/store/index.html 22.2 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.9 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.9 kB
demo/build/petstore/update-pet-with-form/index.html 25 kB
demo/build/petstore/update-pet/index.html 25.4 kB
demo/build/petstore/update-user/index.html 25 kB
demo/build/petstore/upload-file/index.html 24.8 kB
demo/build/petstore/user/index.html 22.9 kB

compressed-size-action

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Visit the preview URL for this PR (updated for commit 2a6b5b7):

https://docusaurus-openapi-36b86--pr1475-tjmhlhtd.web.app

(expires Wed, 27 May 2026 20:36:08 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

OpenAPI 3.1 allows `type` to be an array of type names (e.g. `["string",
"null"]`). The plugin's `getSchemaName` previously returned the raw value,
which downstream rendered as `"string,null"` (or with no separator at all
in some paths). The runtime SchemaItem fix in #1017 only covered the
React render path; the static MDX output remained broken.

Normalize array-form `type` to a `" | "`-joined string and propagate
through format, title, and array wrapping. Single-element arrays unwrap
to the bare type.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sserrata sserrata force-pushed the fix/openapi-31-type-arrays-950 branch from ad5d33b to 2a6b5b7 Compare May 20, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI 3.1 support has a bug w/ nullable types

1 participant