I am writing @ApiProperty's for my objects, and now I have a value which is a Record<EnumA, number>, and I am wondering how I can write the ApiProperty for that. This enum is also used in other places, so I want the schema of the Enum to be included so that the swagger documentation links to the actual enum schema. If this is not possible, how could I change the type of the object value so that it is possible?
#Creating @ApiProperty for Record Enum as key and number as value
6 messages · Page 1 of 1 (latest)
It is possible, but you'll have to do some manual work. Refer to the OpenAPI spec on how to define an object with keys and do the samw thing in ApiProperty({ schema: ..here.. })
Well, the clostest I found is this:
@ApiProperty({
type: 'object',
properties: {
ENUMA1: {
type: 'number',
},
ENUMA2: {
type: 'number',
},
ENUMA3: {
type: 'number',
},
},
})
Which technically works but it means that the keys aren't recognised as values of the schema of EnumA but just strings/property names
Keys can oly be strings. You can dynamically auto-generate the schema from the enum, but there's no way to link it to the enum type if that's what you're trying to do.
Actually, I just foind out that in OpenAPI 3.1, they added a propertyNames keyword, which might do what you are trying to
Oh right, I just found that as well. There's no way to use 3.1 in NestJS though right?