Skip to content

fix: render OpenAPI 3.1 null types as |null - #41

Draft
dotNomad wants to merge 1 commit into
mainfrom
dotnomad/openapi-3-1-nullable-b9385b
Draft

dotNomad wants to merge 1 commit into
mainfrom
dotnomad/openapi-3-1-nullable-b9385b

Conversation

@dotNomad

@dotNomad dotNomad commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

OpenAPI 3.1 specs render nullable fields wrong. 3.1 drops nullable: true and lists "null" in a type array instead, so a field written as type: ["string", "null"] shows up as string,null, and a nullable reference written as anyOf: [{ $ref }, { type: "null" }] isn't recognized as nullable. Now both render the same way 3.0's nullable: true does: string|null, string (date-time)|null, object|null with the object's properties listed under it, and "Or null." after a body's alternatives.

OpenAPI 3.0's nullable: true, including the { nullable: true } anyOf member, still works, and a 3.0 spec renders exactly as it did in v0.6.0. A type array with several non-null types, such as ["string", "integer", "null"], renders as string|integer|null.

Posit Connect needs a release with this before it can move its API spec to 3.1: https://github.com/posit-dev/connect/pull/50607.

Validation

Render Connect's spec in both versions and compare. In a Connect checkout of https://github.com/posit-dev/connect/pull/50607, docs/api/public/openapi.json is 3.1, and git show origin/main:docs/api/public/openapi.json is the same API in 3.0. For each spec, make a temp project with the spec at api/openapi.json and this _quarto.yml:

openapi:
  spec: api/openapi.json
  output: api/index.qmd
  anchor-style: path

then run the pre-render script against it:

QUARTO_PROJECT_DIR=<project> node --stack-size=30000 _extensions/quarto-openapi/openapi-to-markdown.ts

With this branch, the 3.1 spec's api/index.qmd is byte-identical to v0.6.0's output for the 3.0 spec, and the 3.0 spec's output is byte-identical between v0.6.0 and this branch. I checked this for both Connect's public and internal specs. With v0.6.0, the 3.1 specs differ from the 3.0 output on about 3,200 (public) and 5,500 (internal) lines.

🤖 Generated with Claude Code

OpenAPI 3.1 marks nullable fields with type arrays such as
["string", "null"] and nullable references with a { type: "null" }
anyOf/oneOf member. Read both the same way as 3.0's nullable: true,
which keeps working, so a 3.1 field renders as string|null rather
than string,null.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant