-
Notifications
You must be signed in to change notification settings - Fork 516
Open
Labels
Description
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
I have gone through #2898 and #1041
My code looks like this
export enum LogsSearchOperatorType {
EQUAL = 'equal',
NOT_EQUAL = 'not_equal',
}
export class GetApplicationLogsQuery {
...
@ApiPropertyOptional({
enum: LogsSearchOperatorType,
enumName: 'LogsSearchOperatorType',
default: LogsSearchOperatorType.EQUAL,
enumSchema: {
description: 'Comparison operator logs search',
},
description: 'Comparison operator for filter. `equal` or `not_equal`',
})
@IsOptional()
searchOperator?: LogsSearchOperatorType = LogsSearchOperatorType.EQUAL;
}GetApplicationLogsQuery is used as query params in a route.
My goal is to have a default on this enum in this specific context.
While enumSchema has a field default, I do not want to declare the default there because this enum is shared across multiple places.
OAS 3.1.0 now allows default in schema as sibling of $ref
but nestjs/swagger removes all such fields in here:
| return this.omitParamKeys(param); |
And I get
{
"name": "searchOperator",
"required": false,
"in": "query",
"description": "Comparison operator for filter. `equal` or `not_equal`",
"schema": {
"$ref": "#/components/schemas/LogsSearchOperatorType"
}
}Example OAS 3.1 spec that can be tried at https://editor-next.swagger.io/
openapi: "3.1.0"
info:
title: Enum default
version: '0.1.0'
paths:
/products:
get:
parameters:
- in: query
name: color
required: false
schema:
$ref: "#/components/schemas/Color"
default: "black"
responses:
"200":
description: OK
components:
schemas:
Color:
type: string
enum:
- black
- white
- red
- green
- blueDescribe the solution you'd like
Take the default from @ApiProperty and place it in schema
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
Correct defaults for downstream docs and SDK generation