Skip to content

Instantly share code, notes, and snippets.

@clintonb
Last active May 16, 2024 02:04
Show Gist options
  • Save clintonb/16195739bf913e636f9ef4ead4bbbbdb to your computer and use it in GitHub Desktop.
Save clintonb/16195739bf913e636f9ef4ead4bbbbdb to your computer and use it in GitHub Desktop.
nestjs-swagger name attribute bug: https://github.com/nestjs/swagger/issues/2951
{
"schemas": {
"LaneProvisioningTokenDto": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"lane": {
"allOf": [
{
"$ref": "#/components/schemas/NestedLaneDto"
}
]
}
},
"required": [
"token",
"lane"
]
}
}
}
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
export class NestedLaneDto {
@ApiProperty({ type: String })
id: string;
@ApiProperty({ type: String, nullable: true })
name: string | null;
}
export class LaneProvisioningTokenDto {
@ApiProperty({ type: String })
token: string;
// NOTE: The presence of the `name` attribute changes the generated output,
// despite the value being the same as the property name (e.g., the default)
@ApiProperty({ type: NestedLaneDto, name: 'lane' })
@Type(() => NestedLaneDto)
lane: NestedLaneDto;
}
{
"schemas": {
"LaneProvisioningTokenDto": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"lane": {
"$ref": "#/components/schemas/NestedLaneDto"
}
},
"required": [
"token",
"lane"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment