swagger-play
swagger-play copied to clipboard
Question: Swagger Definition is not generating array type for POST object
Hi,
I have a play project and I am using swagger annotations to generate the swagger docs. When I provide the dataType for a POST object to be a List[Object] reads it as a string type instead of List of Objects.
Example: If Foo object is present is models package Foo(id: Long, name: String) then @ApiImplicitParams(Array(new ApiImplicitParam(name = "saveFooObjects", value = "Provide list of Foo Objects", required = true, dataType = "List[models.Foo]", paramType = "body")))
This generates the type as string for the post body
parameters: [{ in: "body", name: "saveFooObjects", description: "Provide list of Foo Objects", required: true, schema: { type: "string" } }]
and throws the following runtime error
Failed to resolve 'List[models.Foo]' into class java.lang.ClassNotFoundException: List[models.Foo] at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60] at play.modules.swagger.PlayReader.typeFromString(PlayReader.java:411) [swagger-play2_2.11-1.5.2.jar:1.5.2]
However, if I specify
@ApiImplicitParams(Array(new ApiImplicitParam(name = "saveFooObjects", value = "Provide list of Foo Objects", required = true, dataType = "models.Foo", paramType = "body")))
This generates the $ref as the foo object.
parameters: [{ in: "body", name: "saveFooObjects", description: "Provide list of Foo Objects", required: true, schema: { $ref: "#/definitions/Foo" } }]
Now how do I get the swagger definition generated as below
parameters: [{ in: "body", name: "saveFooObjects", description: "Provide list of Foo Objects", required: true schema: { type: array items: { $ref: '#/definitions/Foo' } } }]
Am I doing something wrong or do I need to have any additional attributes added in the annotation?
Look at the javadocs for @ApiImplicitParam - it doesn't specify that you can use that notation to mark it as a list. As far as I recall, you can't describe an array unless you do it explicitly (as in, the actual input).
Encountered same issue. Find no code about definition in PlayReader.scala

we should add the logic of reading swagger definition in PlayReader.scala
For now I create a abstract classe which extends java.util.List to bypass this pb...not sure if it is appropriate
abstract class ListString extends java.util.List[String]
ApiImplicitParam(dataType = "models.ListString")
@supaggregator I have this problem too, and I tried your solution but it doesn't seem to be working / doing anything, the params are still passed concatenated with a comma and the parameter name is not repeated, therefore Play thinks that: flow=a&flow=b is a List<String> with 1 String in it, "a, b", instead of a List with two Strings in it, "a" and "b". Can you give me more info about your solution to this issue?