✅ Describing `object` response in swagger
Hey. I have an endpoint that returns an object that looks something like this.
where
Payload
can change depending on the enum value. In typescript or other languages, I'd represent this object as a union type, but since we don't have that in C#, I'd just like to describe the possibilities of this in my swagger documentation6 Replies
First and foremost I'd use generics here, not
object
With Nswag you can use [KnownType]
attribute, but IIRC it only works with derived types
Not with the equivalent of any
With generics, as I mentioned, you should be able to use the [Produces]
attribute on the controller, though
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Ooh, you're right! You could do
as the return type
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Probably with a type alias lol
Ahhh, I'll give that a go. Thanks!