swagger
swagger copied to clipboard
@ApiProperty - Include default value when using `enumName`
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
When using @ApiProperty
like this:
@ApiProperty({ enum: SortOrder, default: SortOrder.DESC })
It renders the OpenAPI json like this:
{
"name": "order",
"required": true,
"in": "query",
"schema": {
"default": "DESC",
"enum": [
"DESC",
"ASC"
],
"type": "string"
}
}
However, when adding a reference to the enum using enumName
instead to avoid duplicate definitions like this:
@ApiProperty({ enum: SortOrder, default: SortOrder.DESC, enumName: 'SortOrder' })
It renders like this:
{
"name": "order",
"required": true,
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortOrder"
}
}
Here we can see that the default
property is lost.
Describe the solution you'd like
Here is a discussion that explains a possible solution: https://github.com/OAI/OpenAPI-Specification/discussions/2948
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
Improve user experience when using software like Postman, Swagger or similar