Last active
May 16, 2024 02:04
-
-
Save clintonb/16195739bf913e636f9ef4ead4bbbbdb to your computer and use it in GitHub Desktop.
nestjs-swagger name attribute bug: https://github.com/nestjs/swagger/issues/2951
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"schemas": { | |
"LaneProvisioningTokenDto": { | |
"type": "object", | |
"properties": { | |
"token": { | |
"type": "string" | |
}, | |
"lane": { | |
"allOf": [ | |
{ | |
"$ref": "#/components/schemas/NestedLaneDto" | |
} | |
] | |
} | |
}, | |
"required": [ | |
"token", | |
"lane" | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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