swagger
swagger copied to clipboard
`example` & `default` properties not behavie as expected
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
The Swagger page is taking default values from the example property in the declaration.
This is especially an issue when the property is an array due to there is no way to really not sent the query param:
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-aprkdl?file=src%2Fapp.controller.ts
Steps to reproduce
Declare an optional property as in:
// input text will have `something` as value
@ApiPropertyOptional({
default: 'default is ignored',
description: 'some string',
example: 'something',
})
q?: string;
// No option selected but the request will include `?options=one`
@ApiPropertyOptional({
description: 'some options',
enum: OPTIONS,
example: OPTIONS[0],
isArray: true,
})
options?: (typeof OPTIONS)[number];
Expected behavior
Default values in SwaggerUI should not be taken from the example property but from the default if there is any
Package version
6.3.0
NestJS version
9.0.0
Node.js version
v18.16.0
In which operating systems have you tested?
- [X] macOS
- [ ] Windows
- [ ] Linux
Other
No response