0

I have a bunch of Exceptions that use the same interface, so it is easier for the frontend to distinct between them from the same endpoint.

I want to be able to document in swagger that MyWeirdExpection has a property type that has the value my-weird-exception (it comes from an string ENUM if that is relevant).

Is this possible to do?

Something like:


enum MyEnum {
   MyWeirdExpection: 'my-weird-exception',
   RegularExpection: 'my-regular-expection'
... more
}



  @ApiProperty({
    description: 'Frontend can react on this property',
    type: String, // <-----------WHAT HERE?
  })
  type: MyEnum.MyWeirdExpection;

Again, my goal is that in the swagger definition, says that MyWeirdExpection.type is the constant 'my-weird-exception'

distante
  • 6,438
  • 6
  • 48
  • 90

1 Answers1

0

The following will provide a type of MyEnum.MyWeirdExpection with the value populated as 'my-weird-exception':

@ApiProperty({
    description: "Search by asset type",
    required: false,
    default: MyEnum.MyWeirdExpection,
    type: MyEnum.MyWeirdExpection
})
type: string | undefined;
distante
  • 6,438
  • 6
  • 48
  • 90
G. Kalber
  • 26
  • 3
  • 'assetType4' should be 'type' – G. Kalber Feb 16 '23 at 20:11
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 24 '23 at 12:37