Skip to content

Add OpenAPI 3.1 support: null type, type arrays#9

Merged
SamyPesse merged 1 commit intomainfrom
nolann/add-partial-support-for-openapi-3.1
Mar 6, 2026
Merged

Add OpenAPI 3.1 support: null type, type arrays#9
SamyPesse merged 1 commit intomainfrom
nolann/add-partial-support-for-openapi-3.1

Conversation

@nolannbiron
Copy link
Copy Markdown
Member

  • Add support for type: 'null' as a standalone type
  • Add support for type arrays (e.g. type: ['string', 'null']) by converting to anyOf

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds OpenAPI 3.1 support to the validator compiler by implementing:

  1. type: 'null' as a standalone schema type that validates a value is strictly null
  2. type arrays (e.g. type: ['string', 'null']) which are converted to an anyOf schema internally

Changes:

  • Added OpenAPINullSchema and OpenAPITypeArraySchema interfaces to the type system; made items optional on OpenAPIArraySchema
  • Added compileNullTypeSchema and compileTypeArraySchema compiler functions and handled the new 'null' case in the switch statement
  • Added snapshot tests for the three new cases (type: 'null', type: ['string', 'null'], type: ['string', 'number']); updated snapshot URL

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/types.ts Adds OpenAPINullSchema and OpenAPITypeArraySchema interfaces; makes items optional on OpenAPIArraySchema
src/compileValueSchema.ts Adds compileNullTypeSchema, compileTypeArraySchema functions, array-type detection, and !schema.items early-return guard
src/tests/compileValueSchema.test.ts Adds snapshot tests for null type and type-array schemas
src/tests/__snapshots__/compileValueSchema.test.ts.snap Adds generated snapshots for the three new test cases
src/tests/__snapshots__/compiler.test.ts.snap Updates the Bun snapshot header URL from a shortened link to the canonical docs URL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/types.ts Outdated
Comment thread src/compileValueSchema.ts Outdated
Comment thread src/compileValueSchema.ts Outdated
Comment thread src/compileValueSchema.ts Outdated
…tems

- Add support for type: 'null' as a standalone type
- Add support for type arrays (e.g. type: ['string', 'null']) by converting to anyOf
- Make array schema items optional to handle arrays without item constraints
- Add OpenAPINullSchema and OpenAPITypeArraySchema types
@nolannbiron nolannbiron force-pushed the nolann/add-partial-support-for-openapi-3.1 branch from 4a01774 to a6788e3 Compare March 5, 2026 22:37
@nolannbiron nolannbiron requested a review from SamyPesse March 5, 2026 22:38
Comment thread src/compileValueSchema.ts
}

/**
* OpenAPI 3.1: type: 'null' as a standalone type.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to test this one well, because I'm wondering if we actually get null as an input value.

@SamyPesse SamyPesse merged commit 02962f2 into main Mar 6, 2026
3 checks passed
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.

3 participants