【发布时间】:2021-05-14 15:16:19
【问题描述】:
TLDR Swagger 不会在 UI 的“示例值”部分中显示所有属性,无论它们是否带注释。
我可能做错了什么,任何帮助将不胜感激!
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
)
在 Swagger UI 中,显示示例值部分
{ "details":{} }
即不显示姓名和电子邮件属性。奇怪的是,单击 Swagger UI 的模型部分确实会显示所有属性。
【问题讨论】:
标签: swagger swagger-ui