问题
I have my pojo defined,
@ApiModelProperty(hidden=true)
@JsonIgnore
public Set<Tank> getTankSet() {
return tankSet;
}
But still I see following json definition in the swagger doc;
"tankSet" : {
"type" : "array",
"items" : {
"$ref" : "Tank"
},
Which causes Swagger UI loading issue "swagger.js:744 Uncaught TypeError: Cannot read property '$ref' of undefined".
How can i overcome this issue?
Edit
POJO
@JsonIgnore
@ApiModelProperty(hidden=true)
public Set<Tank> getTankSet() {
return tankSet;
}
Pom
<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;
Even though i avaoided all complex params in my Model classes, at My endpoint class has "java.util.Set" as one of the query param. Which causes issue in the 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"
},
来源:https://stackoverflow.com/questions/37381492/jsonignore-apimodelpropertyhidden-true-xmltransient-none-are-working-in-s