Swagger 示例值未显示所有属性

Swagger example value not showing all attributes

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

)

https://imgur.com/a/JRgMVh4

在 Swagger UI 中,示例值部分显示

{ "details":{} }

即不显示名称和电子邮件属性。奇怪的是,单击 Swagger 的模型部分 UI 会显示所有属性。

通过简单地使用 jackson-module-kotlin 并从数据中删除所有注释、构造函数等,证明了 Jackson 和 Swagger "just work" 类

https://github.com/FasterXML/jackson-module-kotlin

spring.main.lazy-初始化=false

在 application.properties 中,将延迟初始化设置为 false 对我有用。