TLDR Swagger isn't showing all attributes in the Example Value section of the UI, irrespective of whether they are annotated or not.
I'm probably doing something wrong, any help would be much appreciated!
import com.codahale.metrics.annotation.ResponseMetered
import com.codahale.metrics.annotation.Timed
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import javax.validation.Valid
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response
@Api(
tags = ["foobar"],
description = "foobar")
@Path("/v1/user")
class FooResource {
@POST
@Path("v1/user")
@Produces(MediaType.APPLICATION_JSON)
@Timed
@ResponseMetered
@ApiOperation("Foo bar")
fun lisApiUser(@Valid user: User): Response {
throw RuntimeException("foo")
}
}
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
@JsonIgnoreProperties(ignoreUnknown = true)
//@ApiModel makes no difference
data class User @JsonCreator constructor(
@JsonProperty("name")
// @ApiModelProperty(name = "name", value = "John Smith", example = "John Smith") makes no difference
// @field:ApiModelProperty(name = "name", value = "John Smith", example = "John Smith") makes no difference
val name: String, //doesn't show in Swagger UI
@JsonProperty("details")
val details: Details //shows in Swagger UI
)
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
@JsonIgnoreProperties(ignoreUnknown = true)
//@ApiModel makes no difference
data class Details @JsonCreator constructor(
@JsonProperty("email")
// @ApiModelProperty(name = "email", value = "foo@example.com") makes no difference
// @field:ApiModelProperty(name = "email", value = "foo@example.com", example = "foo@example.com") makes no difference
val email: String //doesn't show in Swagger UI
)
https://i.sstatic.net/YBb1O.jpg
In the Swagger UI, the Example Value section displays
{ "details":{} }
ie name and email attributes are not displayed. Oddly, clicking the Model section of the Swagger UI does display all attributes.
Turns out both Jackson and Swagger "just work" by simply using the jackson-module-kotlin and removing all the annotations, constructors etc from the data classes