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

时间:2016-05-18 03:52:00

标签: rest jax-rs swagger swagger-ui swagger-2.0

我有自动生成的Swagger json docs(使用jaxrs-analyzer插件)。当我尝试加载UI时,我得到了 跟随错误。

swagger.js:744 Uncaught TypeError: Cannot read property '$ref' of undefined

在我有的json中,定义了复杂的数组类型。 (这是有效的json)

 {
        "type" : "array",
        "description" : "xx",
        "uniqueItems" : true,
        "paramType" : "query",
        "name" : "grade"

}

"contactDetails" : {
          "type" : "array",
          "items" : {
            "$ref" : "ContactDetail"
          },
          "uniqueItems" : true
        },

如何解决此错误?

<swagger-jaxrs-2-10-version>1.3.12</swagger-jaxrs-2-10-version>
        <swagger-annotations-version>1.5.3-M1</swagger-annotations-version>



<plugin>
                <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
                                /testdbwar/apidocs
                                -apiBasePath /testwar/rest
                                -swaggerUiPath
                                ${project.build.directory}/
                            </additionalparam>
                        </configuration>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>

                </executions>

            </plugin>
            <plugin>
                <groupId>com.sebastian-daschner</groupId>
                <artifactId>jaxrs-analyzer-maven-plugin</artifactId>
                <version>0.9</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>analyze-jaxrs</goal>
                        </goals>
                        <configuration>
                            <!-- Available backends, defaults to plaintext -->
                            <!-- <backend>plaintext</backend> -->
                            <backend>swagger</backend>
                        </configuration>
                    </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>testwar/**/*</include>
                                <include>**/*.war</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

修改;

我的pojo中有一个get方法; (就像我有几个获取方法一样)

@JsonIgnore
    public Set<HistoryTankSystem> getHistoryStatusSet() {
        return historyStatusSet;
    }

然后在json我得到;

"historyStatusSet" : {
          "type" : "array",
          "items" : {
            "$ref" : "HistoryTankSystem"
          },
          "uniqueItems" : true
        }
      },

这会导致上述问题。

在json中,我看到它生成1.2定义;

{
  "apiVersion" : "1",
  "swaggerVersion" : "1.2",
  "basePath" : "/testwar/rest",
  "resourcePath" : "/TankSystems",
  "apis" : [ {

0 个答案:

没有答案