@JsonIgnore,@ ApiModelProperty(hidden = true),@ XmlTransient没有在swagger json

时间:2016-05-23 01:39:24

标签: json jax-rs swagger swagger-ui

我定义了我的pojo,

@ApiModelProperty(hidden=true) 
@JsonIgnore
    public Set<Tank> getTankSet() {
        return tankSet;
    }

但是我仍然在swagger doc中看到了json定义;

"tankSet" : {
      "type" : "array",
      "items" : {
        "$ref" : "Tank"
      },

导致Swagger UI加载问题“swagger.js:744 Uncaught TypeError:无法读取未定义的属性'$ ref'”。

我如何克服这个问题?

修改

POJO

@JsonIgnore
@ApiModelProperty(hidden=true)  

    public Set<Tank> getTankSet() {
        return tankSet;
    }

聚甲醛

<dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-core</artifactId>
      <version>1.5.9</version>
   </dependency>

    <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-jaxrs_2.10</artifactId>
            <version>${swagger-jaxrs-2-10-version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

....

        <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <executions>
                    <execution>
                        <id>generate-service-docs</id>
                        <phase>generate-resources</phase>
                        <configuration>
                            <doclet>com.carma.swagger.doclet.ServiceDoclet</doclet>
                            <docletArtifact>
                                <groupId>com.carma</groupId>
                                <artifactId>swagger-doclet</artifactId>
                                <version>1.0.4.1</version>
                            </docletArtifact>
                            <reportOutputDirectory>src/main/webapp</reportOutputDirectory>
                            <useStandardDocletOptions>false</useStandardDocletOptions>
                            <additionalparam>-apiVersion 1 -docBasePath
                                /test2dbwar/apidocs
                                -apiBasePath /test2dbwar/rest
                                -swaggerUiPath
                                ${project.build.directory}/
                            </additionalparam>
                        </configuration>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>

                </executions>

            </plugin>

            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/webapp/apidocs</directory>
                            <includes>
                                <include>classes/**/*</include>
                                <include>test2dbwar/**/*</include>
                                <include>**/*.war</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <debug>true</debug>
                    <debuglevel>lines,vars,source</debuglevel>
                </configuration>
            </plugin>


Edit;

尽管我在我的Model类中找到了所有复杂的参数,但在我的端点类中,“java.util.Set”作为查询参数之一。这导致了json的问题。

@GET
@NoCache
public Response getItems(
    @QueryParam("start") @DefaultValue("0") Integer startPosition,
    @QueryParam("max") @DefaultValue("10") Integer maxResult, 
    @QueryParam("installDate") java.time.LocalDateTime installDate,
    @QueryParam("historyStatusSet") java.util.Set historyStatusSet,
    @QueryParam("format") @DefaultValue("list") String format
) {

的Json

{
        "type" : "array",
        "description" : "list TankSystems with given historyStatusSet (separated by commas)",
        "uniqueItems" : true,
        "paramType" : "query",
        "name" : "tankSet"
      },

0 个答案:

没有答案