首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >springfox ApiModelProperty位置排序不起作用

springfox ApiModelProperty位置排序不起作用
EN

Stack Overflow用户
提问于 2020-08-27 21:13:52
回答 2查看 1.5K关注 0票数 3

在我的spring boot应用程序中,我无法使用@ApiModel注释类上正确排序的字段来管理我的swagger JSON。

首先,我将springfox lib导入到我的pom.xml中:

代码语言:javascript
复制
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>

其次,我创建了SwaggerConfig.java:

代码语言:javascript
复制
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket swaggerSpringMvcPlugin() {
        return new Docket(DocumentationType.SWAGGER_2)  
                  .select()                                  
                  .apis(RequestHandlerSelectors.basePackage("my.package.to.enable.swagger.doc"))           
                  .paths(PathSelectors.any())       
                  .build()
                  .host("http://localhost:8080");
    }
}

第三,我创建了由@ApiModel注释的PersonDTO

代码语言:javascript
复制
@ApiModel(value = "Person", description = "Person entity definition")
public class PersonDTO {

    @ApiModelProperty(value="Entity unique ID", position=0)
    public Long id;

    @ApiModelProperty(value="Person's number, useful to provide a convenient way to quickly communicate a person's reference", position=1)
    public Integer number;
    
    @ApiModelProperty(value="Person's first name", position=2)
    public String firstName;
    
    @ApiModelProperty(value="Person's last name", position=3)
    public String lastName;
    
}

然后,当我在url http://localhost:[port]/[servlet-context-path]/v2/api-docs请求Json输出时,位置顺序似乎不起作用:

代码语言:javascript
复制
"definitions": {
    "Person": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string",
          "description": "Person's first name"
        },
        "id": {
          "type": "integer",
          "format": "int64",
          "description": "Entity unique ID"
        },
        "lastName": {
          "type": "string",
          "description": "Person's last name"
        },
        "number": {
          "type": "integer",
          "format": "int32",
          "description": "Person's number, useful to provide a convenient way to quickly communicate a person's reference"
        }
      },
      "title": "Person",
      "description": "Person entity definition"
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-28 14:36:28

这在3.0.0中被破坏了请参阅https://github.com/springfox/springfox/issues/3391

票数 4
EN

Stack Overflow用户

发布于 2021-05-05 19:27:19

使用@RequestBody在控制器方法中工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63616811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档