fix(openapi3): apply @encode to the inner type of nullable properties in OpenAPI 3.1 and 3.2 - #12016
Open
om singhal (Om-singhaI) wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot started reviewing on behalf of
om singhal (Om-singhaI)
September 18, 2026 16:57
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, includes regression tests for the new branch behavior, and provides an appropriate fix changeset for the user-visible emitter output correction.
Pull request overview
Fixes OpenAPI 3.1/3.2 emission for @encode applied to nullable unions (T | null) by ensuring encoding is applied to the non-null schema inside anyOf, matching the intended JSON Schema semantics and avoiding schemas that reject null (or all values for type-changing encodes).
Changes:
- Apply
@encodeto the non-null member ofanyOf: [T, { type: "null" }]in the 3.1 helper sonullremains valid and encoded types/formats land in the right place. - Update encoding-field selection to look through nullable unions so
bytes | nullcorrectly usescontentEncodinginstead offormat. - Add targeted tests for OpenAPI 3.1.0 and 3.2.0, plus a Chronus
fixchangeset for@typespec/openapi3.
File summaries
| File | Description |
|---|---|
| packages/openapi3/src/openapi-helpers-3-1.ts | Applies encoding to the non-null anyOf member for nullable unions and fixes encoding field selection for nullable bytes. |
| packages/openapi3/test/nullable-properties.test.ts | Adds regression tests covering nullable properties/parameters with @encode for OpenAPI 3.1.0 and 3.2.0. |
| .chronus/changes/fix-openapi3-encode-nullable-property-2026-09-18.md | Adds a fix changeset documenting the user-visible behavior correction in @typespec/openapi3. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes #12015
In OpenAPI 3.1 and 3.2,
T | nullis emitted asanyOf: [T, { type: "null" }].applyEncodingran on that wrapper, so the encodedtypeandformatlanded next toanyOfwhileTkept its original type. The schema then rejectednull, and for unixTimestamp, seconds and@encode(string)it matched nothing at all.bytes | nullalso gotformatwhere it should getcontentEncoding.3.0 isn't affected because it flattens
T | nullinto one schema withnullable: true.Changes
openapi-helpers-3-1.ts, when the property has@encodeand the schema isanyOf: [T, { type: "null" }], the encoding goes onTand the null member is left alone. Properties and parameters both use this helper.getEncodingFieldNamelooks throughT | nullsobytes | nullkeepscontentEncoding.Testing
worksFor(["3.1.0", "3.2.0"])cases innullable-properties.test.tsfor unixTimestamp, rfc7231, seconds,@encode(string)onint64, base64urlbytesand a nullable query parameter. All 12 fail on main and pass with the fix.packages/openapi3/test(primitive types, unions, arrays, parameters, examples and others): 1222 passed.nullboth pass. 3.0 output is unchanged.