首页 > 解决方案 > Springfox swagger ApiModelProperty 值未显示在对象上

问题描述

所以我在正在构建的文档中遇到了 Springfox Swagger 的这个问题。我使用的是 3.0.0 版。我有一个看起来像这样的课程

    @ApiModel(value="foo")
    public class foo {
      @ApiModelProperty(value="Item A")
      string a;
      @ApiModelProperty(value="Item Object B")
      MyObj b;
    }

    @ApiModel(value="myObj")
    public class MyObj {
     @ApiModelProperty(value="Item X")
     int x;
     @ApiModelProperty(value="Item Y")
     int y;
   }

   All have generic getters and setters

但是,当我在我的 spring boot 应用程序上查看 swagger ui 中的模式模型页面时,参数 b 的值没有显示出来。我不能将描述放在 MyObj 中,因为这是一个在多个实例中使用的通用类,并且描述会根据使用情况而变化。

编辑:任何原始类型(例如 string 或 int)的描述都可以正常工作,只要使用对象即可。

编辑 2:我使用了 springfox-petstore 示例并添加了注释。它似乎适用于对象数组,但不适用于对象本身

category    Category{...}
id  integer($int64)
example: 10

ID for Pet
name*   string
example: doggie

Pet Name
photoUrls*  [

Photo URLs for Pets
string]
status  string

pet status in the store
Enum:
[ available, pending, sold ]
tags    [

Array of Tags
Tag{
id  integer($int64)
name    string
}]
}```

标签: swaggeropenapispringfox

解决方案


尝试使用公共访问变量string aMyObj b


推荐阅读