I'm using Nest.js with Swagger and the Swagger CLI enabled. I have an endpoint in a controller which has an optional boolean query parameter: includeAll
that defaults to false. The endpoint looks like:
@Get()
findAll(
@Query('includeArtifacts', ParseOptionalBool)
includeArtifacts = false,
) {
return this.toursService.findAll({ includeArtifacts });
}
I'm using an Injectable Pipe Transform similar to what is described in the docs to parse the optional boolean value seen here:
export const toBoolean = (value?: string): boolean => {
value = value?.toLowerCase();
return value === 'true' || value === '1';
};
@Injectable()
export class ParseOptionalBool implements PipeTransform {
transform(value?: any, metadata?: ArgumentMetadata): any {
return toBoolean(value);
}
}
Everything functions successfully; however, as seen below when I view the endpoint in Swagger there is no mention of my includeArtifacts
endpoint.