Replies: 1 comment 1 reply
-
You want to look into discriminator and all of. The discriminator field here would be your entity type. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Does go-swagger support generation of swagger spec for a request parameter (in body) having an array of objects? If yes, how should I annotate the Golang structs?
Illustration or sample JSON I would like to support:
{
streams[]:
{
entityType: 1,
f1:"foobar",
f2:"hello",
},
{
entityType: 1,
f1:"foo baz",
f2:"hello 2",
},
{
entityType: 2,
f1:"sound",
s1:123,
}
{
entityType: 3,
f1:"picture2",
t1:1.23,
}
}
The closest Golang struct definition for above are:
type A struct {
EntityType int
json:"entityType"
F1 string
json:"f1"
F2 string
json:"f2"
}
structs B & C is similar to A, see the JSON above for entityType 2 & 3 for the field definitions.
Another struct I made so I can wrap them under the "streams" field:
type xWrapper struct {
Streams []interface{}
json:"streams"
}
The Parameter body should be something like:
type paramWrapper struct {
// in:body
Body xWrapper
}
My question is, how do I specify that the elements of "streams" can only be of either type A, B or C structs? (is this use-case supported?)
Beta Was this translation helpful? Give feedback.
All reactions