Reputation: 415
I'm trying to use Swagger to document my REST API. Following this example, I annotate the REST Endpoints like this:
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 was expecting to get "Model" like but I get only the String "CreateItemRequest" as Data Type. Not the properties of the case class CreateItemRequest.
Greetings, Daniel
Upvotes: 5
Views: 5070
Reputation: 595
You should use the full namespace in the dataType attribute. For example:
@ApiImplicitParam(dataType = "org.test.CreateItemRequest")
Upvotes: 9
Reputation: 107
Try using this annotation @JsonAutoDetect
and @JsonIgnoreProperties(ignoreUnknown = true)
before your class and then add @JsonPropety
for each properties you want to show.
Make sure that in your route definition you call your method like :
GET url controllers.foo.YourMethod(param: type)
More example here.
Hope this will help you.
Upvotes: 0
Reputation: 79
try to annotate your models with the swagger annotations as well, like shown here:
https://github.com/swagger-api/swagger-core/blob/master/samples/scala-play2/app/models/Pet.scala
your annotation ApiModel(name="CreateItemRequest") match the annotation @ApiImplicitParam(dataType = "CreateItemRequest")
Cheers, Johannes
Upvotes: 0