Swagger示例值未显示所有属性

问题描述 投票:0回答:1

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 = "[email protected]") makes no difference
//        @field:ApiModelProperty(name = "email", value = "[email protected]", example = "[email protected]") makes no difference
        val email: String //doesn't show in Swagger UI

)

https://imgur.com/a/JRgMVh4

在Swagger UI中,将显示“示例值”部分

{ "details":{} }

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

swagger swagger-ui
1个回答
0
投票

通过简单地使用jackson-module-kotlin并从数据类中删除所有注释,构造函数等,证明Jackson和Swagger“正常工作”

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

© www.soinside.com 2019 - 2024. All rights reserved.