feat(openapi): support style and explode serialization for path parameters - #940
Open
lx3133584 wants to merge 1 commit into
Open
feat(openapi): support style and explode serialization for path parameters#940lx3133584 wants to merge 1 commit into
lx3133584 wants to merge 1 commit into
Conversation
…eters Fixes fastify#912 Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds OpenAPI path-parameter style and explode serialization support. It also introduces unrelated nullable-schema conversion with correctness issues.
Changes:
- Forward path serialization options.
- Test path serialization.
- Convert null-containing schemas to OpenAPI 3.0 nullable schemas.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/spec/openapi/utils.js |
Adds path serialization and nullable conversion. |
test/spec/openapi/schema.test.js |
Tests both behaviors. |
Suppressed comments (2)
lib/spec/openapi/utils.js:558
- Converting
type: 'null'to{ nullable: true }does not preserve the schema. In OpenAPI 3.0,nullableonly adds null to an explicitly declaredtype; withouttype, this schema is effectively unconstrained rather than null-only. Either reject this unsupported 3.0 construct or emit a constrained null-only representation instead of deleting its sole type constraint.
if (value === 'null') {
openapiSchema.nullable = true
delete openapiSchema.type
continue
lib/spec/openapi/utils.js:567
- For multiple remaining types, the generated schema has
anyOfbut no top-leveltype. OpenAPI 3.0 therefore does not apply the top-levelnullable: true, andnullis rejected even though the input explicitly allows it. Movenullable: trueonto one typedanyOfbranch (and remove it from the parent), then update the assertion to verify that representation.
} else if (remainingTypes.length > 1) {
openapiSchema.anyOf = remainingTypes.map(t => ({ type: t }))
delete openapiSchema.type
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| continue | ||
| } | ||
|
|
||
| if (key === 'type') { |
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.
Problem
Path parameters in OpenAPI 3.0 did not support
styleandexplodeserialization options, whereas query parameters already supported them.Root Cause
In
lib/spec/openapi/utils.js,plainJsonObjectToOpenapi3forwardedstyleandexplodeproperties on query/cookie/header containers, but omitted them forcase 'path'.Fix
Forward
jsonSchema.styleandjsonSchema.explodeto the OpenAPI path parameter definition when specified.Testing
test/spec/openapi/schema.test.jsvalidatingstyleandexplodepath parameter serialization withSwagger.validate().