Add OpenAPI 3.1 support: null type, type arrays#9
Merged
Conversation
Member
nolannbiron
commented
Mar 5, 2026
- Add support for type: 'null' as a standalone type
- Add support for type arrays (e.g. type: ['string', 'null']) by converting to anyOf
There was a problem hiding this comment.
Pull request overview
This PR adds OpenAPI 3.1 support to the validator compiler by implementing:
type: 'null'as a standalone schema type that validates a value is strictlynulltypearrays (e.g.type: ['string', 'null']) which are converted to ananyOfschema internally
Changes:
- Added
OpenAPINullSchemaandOpenAPITypeArraySchemainterfaces to the type system; madeitemsoptional onOpenAPIArraySchema - Added
compileNullTypeSchemaandcompileTypeArraySchemacompiler functions and handled the new'null'case in theswitchstatement - 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.
…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
4a01774 to
a6788e3
Compare
SamyPesse
approved these changes
Mar 6, 2026
| } | ||
|
|
||
| /** | ||
| * OpenAPI 3.1: type: 'null' as a standalone type. |
Member
There was a problem hiding this comment.
We'll have to test this one well, because I'm wondering if we actually get null as an input value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.