Skip to content

feat(openapi): support style and explode serialization for path parameters - #940

Open
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/path-params-serialization
Open

feat(openapi): support style and explode serialization for path parameters#940
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/path-params-serialization

Conversation

@lx3133584

Copy link
Copy Markdown

Problem

Path parameters in OpenAPI 3.0 did not support style and explode serialization options, whereas query parameters already supported them.

Root Cause

In lib/spec/openapi/utils.js, plainJsonObjectToOpenapi3 forwarded style and explode properties on query/cookie/header containers, but omitted them for case 'path'.

Fix

Forward jsonSchema.style and jsonSchema.explode to the OpenAPI path parameter definition when specified.

Testing

  • Added unit tests in test/spec/openapi/schema.test.js validating style and explode path parameter serialization with Swagger.validate().
  • Verified all 268 test suites (100% coverage) and TypeScript type tests pass cleanly.

…eters

Fixes fastify#912

Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, nullable only adds null to an explicitly declared type; without type, 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 anyOf but no top-level type. OpenAPI 3.0 therefore does not apply the top-level nullable: true, and null is rejected even though the input explicitly allows it. Move nullable: true onto one typed anyOf branch (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.

Comment thread lib/spec/openapi/utils.js
continue
}

if (key === 'type') {
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.

2 participants