ImpagentParam Swagger data type model with Play Framework

I am trying to use Swagger to document my REST API. Following this example , I comment on the REST endpoints as follows:

case class CreateItemRequest(title: String, body: String) @ApiOperation(value = "Create a new item", httpMethod = "POST", response = classOf[Item]) @ApiImplicitParams(Array(new ApiImplicitParam(dataType = "CreateItemRequest", paramType = "body", name = "body", required = true, allowMultiple = false, value = "The item object to create"))) def create( @ApiParam(value = "Hash of the user", required = true) @QueryParam("userhash") userhash: String ) 

And I expected to get "Model" as this but I only get String "CreateItemRequest" as the data type. Not properties of the class class CreateItemRequest.

Hi Daniel

+5
source share
3 answers

You must use the full namespace in the dataType attribute. For example: @ApiImplicitParam(dataType = "org.test.CreateItemRequest")

+9
source

try annotating your models with swagger annotations as well, as shown here:

https://github.com/swagger-api/swagger-core/blob/master/samples/scala-play2/app/models/Pet.scala

Your ApiModel annotation (name = "CreateItemRequest") matches the @ApiImplicitParam annotation (dataType = "CreateItemRequest")

Cheers, Johannes

0
source

Try using this annotation @JsonAutoDetect and @JsonIgnoreProperties(ignoreUnknown = true) in front of your class, and then add @JsonPropety for each property that you want to show.

Make sure you call your method in the route definition as follows:

 GET url controllers.foo.YourMethod(param: type) 

An example is here .

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1214563/


All Articles