How can Empty-Valued and Nullable Parameters such as query param metadata
in a route such as GET /foo?metadata
be documented in @nestjs/swagger? Using either readonly metadata?: null;
or readonly metadata?: null;
in a route @Query()
dto class prompts the user in the generated swagger to enter a string
value for the metadata
property. This is confusing because no value is meant to be passed to this query param. Also trying @ApiProperty({ required: false, default: true, nullable: true }) readonly metadata?: boolean
provides a dropdown but does not add the Send empty value
checkbox that would be in swagger/oas3.
In Swagger/OAS3 this would be documented as:
parameters:
- in: query
name: metadata
schema:
type: boolean
allowEmptyValue: true
The key here would be the property allowEmptyValue
. How can allowEmptyValue
be defined in a TypeScript class representing a @Query()
dto either through @nest/swagger
decorators or class-validator decorators? It looks like BaseParemeterObject has the property allowEmptyValue: boolean
, but how can that be used with an individual query dto param property?
Update:
I am able to use ApiQuery()
decorator on a route in a @Controller()
as follows to get the correct functionality:
@ApiQuery({ name: 'metadata', allowEmptyValue: true, type: Boolean, required: false })
But how could I get that same functionality in a a class
DTO representing the Query()
?