Skip to content

fix(swagger-types-mapper): place multipleOf inside parameter schema#3882

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
yogeshwaran-c:fix/swagger-types-mapper-missing-schema-keys
Apr 28, 2026
Merged

fix(swagger-types-mapper): place multipleOf inside parameter schema#3882
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
yogeshwaran-c:fix/swagger-types-mapper-missing-schema-keys

Conversation

@yogeshwaran-c

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

When a parameter (e.g. @ApiQuery, @ApiParam) is declared with a multipleOf constraint without an explicit schema host, the value is left at the parameter top level instead of being moved into parameter.schema. The resulting OpenAPI parameter object is invalid because OAS numeric validation keywords like multipleOf belong inside the parameter's schema, alongside minimum/maximum/etc.

Example input:

@ApiQuery({ name: 'count', type: Number, multipleOf: 5 })

Current output (truncated):

{
  "name": "count",
  "in": "query",
  "required": true,
  "multipleOf": 5,           // <-- wrong location
  "schema": { "type": "number" }
}

The same problem exists for array-typed parameters — multipleOf is dropped entirely from the generated schema.

SwaggerTypesMapper#getSchemaOptionsKeys enumerates the SchemaObject keys that should be promoted from a parameter's top-level options into its schema block. multipleOf is missing from that list even though it is declared on SchemaObject and is generated by the plugin for DTOs (e.g. via @IsDivisibleBy).

What is the new behavior?

multipleOf is now included in the schema options key list, so it is placed under parameter.schema for both scalar and array parameters, matching how minimum, maximum, exclusiveMinimum, etc. are already handled.

{
  "name": "count",
  "in": "query",
  "required": true,
  "schema": { "type": "number", "multipleOf": 5 }
}

Additional context (optional)

Added a small SwaggerTypesMapper unit test covering both the scalar and the array-parameter codepaths. The existing swagger-explorer suite (53 tests) continues to pass.

When a parameter (e.g. @apiquery, @ApiParam) is declared with a
`multipleOf` constraint without an explicit `schema` host, the value
was kept at the parameter top level instead of being moved into
`parameter.schema`. This produced an invalid OpenAPI parameter object
because numeric validation keywords like `multipleOf` belong inside the
parameter's schema.

Add `multipleOf` to the list of recognised schema option keys so it is
correctly placed under `schema` for both scalar and array parameters,
mirroring the existing handling of `minimum`, `maximum`,
`exclusiveMinimum`, etc.
@kamilmysliwiec kamilmysliwiec merged commit f10b1e2 into nestjs:master Apr 28, 2026
1 check passed
@kamilmysliwiec

Copy link
Copy Markdown
Member

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants