Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swagger annotations to document request body of array type

I have a resource that accepts POST requests with JSON body of array type, for example:

[
  { "foo": "bar" },
  { "foo": "baz" },
  ...
]

To document non-collection type using Swagger annotations I can do:

@ApiImplicitParams(Array(
  new ApiImplicitParam(paramType = "body", dataType = "my.Request", required = true)
))

How to do the same for array body type, e.g. Seq[my.Request]?

like image 238
Tvaroh Avatar asked Oct 21 '25 17:10

Tvaroh


1 Answers

It can be done by introducing a surrogate trait that extends Java's standard library list:

trait ArrayBody extends java.util.List[ArrayElementType]

And then in the endpoint annotations:

@ApiImplicitParams(Array(
  new ApiImplicitParam(paramType = "body", dataType = "foo.bar.ArrayBody", required = true)
))
like image 154
Tvaroh Avatar answered Oct 24 '25 08:10

Tvaroh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!