Model schema of return type not shown in swagger-ui

1,858 views
Skip to first unread message

David Wood

unread,
Aug 5, 2014, 9:38:39 AM8/5/14
to swagger-sw...@googlegroups.com


I have a class as follows:

@ApiModel( value = "JSONCreatePolicyResponse", description = "The response to a successful policy creation request")
public class JSONCreatePolicyResponse extends JSONStatus {... }

which is returned by:

    @POST
    @Path("/create")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "/create", notes="Creates a new policy. ", response=JSONCreatePolicyResponse.class)
    public JSONStatus createPolicy(JSONPolicy policy) {

The swagger-ui properly shows the JSONPolicy schema for the input, but only shows the type name for the output.  I'm very much new to swagger so it is likely I've not done something correctly.  Any help appreciated.


Ron

unread,
Aug 5, 2014, 9:41:42 AM8/5/14
to swagger-sw...@googlegroups.com
Can you share the Swagger output generated for that API?


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Aug 5, 2014, 9:43:04 AM8/5/14
to swagger-sw...@googlegroups.com
Also, can you mention which swagger dependency and version you use?

David Wood

unread,
Aug 5, 2014, 9:43:14 AM8/5/14
to swagger-sw...@googlegroups.com

Also, I tried matching the return type in the annotation what that of the method


    @POST
    @Path("/create")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "/create", notes="Creates a new policy. ", response=JSONStatus.class)
    public JSONStatus createPolicy(JSONPolicy policy) { ... }

But that did not change the behavior.


David Wood

unread,
Aug 5, 2014, 9:56:18 AM8/5/14
to swagger-sw...@googlegroups.com
I can see the swagger is not producing JSONStatus or JSONCreatePolicyResponse in the models section below:

{"apiVersion":"0.0.1","swaggerVersion":"1.2","basePath":"http://localhost:8080/WPML-Service/api","resourcePath":"/policy",
"apis":[{"path":"/policy/update","operations":[{"method":"POST","summary":"/update",
"notes":"Updates the policy with the given repository identifier to the new value provided.",
"type":"com.ibm.watson.pml.service.json.JSONStatus","nickname":"updatePolicy","produces":["application/json"],
"consumes":["application/json"],"parameters":[{"name":"body",
"description":"Provides both the new policy and the existing repository identifier","required":false,"type":
"JSONPolicy","paramType":"body","allowMultiple":false}]}]},{"path":"/policy/create",
"operations":[{"method":"POST","summary":"/create","notes":"Creates a new policy. ",
"type":"com.ibm.watson.pml.service.json.JSONStatus","nickname":"createPolicy","produces":["application/json"],
"consumes":["application/json"],"parameters":[{"name":"body","required":false,"type":"JSONPolicy","paramType":"body","allowMultiple":false}]}]},
{"path":"/policy/read","operations":[{"method":"GET","summary":"/read","notes":"Reads 1 or all policies.",
"type":"com.ibm.watson.pml.service.policy.JSONReadPolicyResponse","nickname":"readPolicies",
"produces":["application/json"],"consumes":["*/*"],"parameters":[{"name":"id",
"description":"The identifier of returned in a create call. If not provide, all policies are read.","required":false,"type":"string",
"paramType":"query","allowMultiple":false}]}]},{"path":"/policy/delete",
"operations":[{"method":"POST","summary":"/delete","notes":"Deletes 1 or more policies.",
"type":"com.ibm.watson.pml.service.json.JSONStatus","nickname":"deletePolicies","produces":["application/json"],
"consumes":["application/json"],"parameters":[{"name":"body","required":false,"type":"Map","paramType":"body",
"allowMultiple":false}]}]}],"models":{"JSONPolicy":{"id":"JSONPolicy","description":"Policy specification",
"required":["type","language","policy"],"properties":{"repID":{"type":"string","description":
"ID associated with a stored policy. Currently only used on update requests."},"name":{"type":"string"},"description":{"type":"string"},
"type":{"type":"string","description":"Type of policy. One of Obligation or Authorization."},"language":{"type":"string","description":
"Language of this policy. One of CIM-SPL or Groovy."},"policy":{"type":"string","description":"Policy itself."}}},"Map":
{"id":"Map","properties":{"empty":{"type":"boolean"}}}
}}

Ron

unread,
Aug 5, 2014, 10:00:05 AM8/5/14
to swagger-sw...@googlegroups.com
What about the dependency and the version?


--

David Wood

unread,
Aug 5, 2014, 10:02:52 AM8/5/14
to swagger-sw...@googlegroups.com
I'm running tomcat7 inside eclipse on Windows7.   I'm not using maven to do the build, but am using jars listed below in the project which are from 1.3.7 swagger-core.  I pieced this together to integrate with an existing project, so perhaps there is a problem there (I'm also new to maven).  However, I get no warnings from tomcat7 (on the eclipse console).

/WPML-Service/WebContent/WEB-INF/lib/antlr-2.7.7.jar
/WPML-Service/WebContent/WEB-INF/lib/asm-3.1.jar
/WPML-Service/WebContent/WEB-INF/lib/commons-lang-2.4.jar
/WPML-Service/WebContent/WEB-INF/lib/derbyclient.jar
/WPML-Service/WebContent/WEB-INF/lib/groovy-all-2.3.2.jar
/WPML-Service/WebContent/WEB-INF/lib/guava-15.0.jar
/WPML-Service/WebContent/WEB-INF/lib/jackson-annotations-2.2.0.jar
/WPML-Service/WebContent/WEB-INF/lib/jackson-core-2.2.0.jar
/WPML-Service/WebContent/WEB-INF/lib/jackson-databind-2.2.0.jar
/WPML-Service/WebContent/WEB-INF/lib/jersey-client-1.17.1.jar
/WPML-Service/WebContent/WEB-INF/lib/jersey-core-1.17.1.jar
/WPML-Service/WebContent/WEB-INF/lib/jersey-json-1.17.1.jar
/WPML-Service/WebContent/WEB-INF/lib/jersey-server-1.17.1.jar
/WPML-Service/WebContent/WEB-INF/lib/jersey-servlet-1.17.1.jar
/WPML-Service/WebContent/WEB-INF/lib/joda-convert-1.2.jar
/WPML-Service/WebContent/WEB-INF/lib/joda-time-2.2.jar
/WPML-Service/WebContent/WEB-INF/lib/JSON4J_Apache.jar
/WPML-Service/WebContent/WEB-INF/lib/json4s-ast_2.10-3.2.9.jar
/WPML-Service/WebContent/WEB-INF/lib/json4s-core_2.10-3.2.9.jar
/WPML-Service/WebContent/WEB-INF/lib/json4s-ext_2.10-3.2.9.jar
/WPML-Service/WebContent/WEB-INF/lib/json4s-jackson_2.10-3.2.9.jar
/WPML-Service/WebContent/WEB-INF/lib/json4s-native_2.10-3.2.9.jar
/WPML-Service/WebContent/WEB-INF/lib/jsr305-2.0.1.jar
/WPML-Service/WebContent/WEB-INF/lib/jsr311-api-1.1.1.jar
/WPML-Service/WebContent/WEB-INF/lib/logback-classic-1.0.1.jar
/WPML-Service/WebContent/WEB-INF/lib/logback-core-1.0.1.jar
/WPML-Service/WebContent/WEB-INF/lib/paranamer-2.6.jar
/WPML-Service/WebContent/WEB-INF/lib/scala-actors-2.10.0.jar
/WPML-Service/WebContent/WEB-INF/lib/scala-compiler-2.10.0.jar
/WPML-Service/WebContent/WEB-INF/lib/scala-library-2.10.0.jar
/WPML-Service/WebContent/WEB-INF/lib/scala-reflect-2.10.0.jar
/WPML-Service/WebContent/WEB-INF/lib/scalap-2.10.0.jar
/WPML-Service/WebContent/WEB-INF/lib/slf4j-api-1.6.3.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-annotations-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-core_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-jaxrs_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-jersey-jaxrs_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-jersey2-jaxrs_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-oauth2-server_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-servlet_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-utils_2.10-1.3.7.jar

Ron

unread,
Aug 5, 2014, 10:05:16 AM8/5/14
to swagger-sw...@googlegroups.com
Which JAX-RS implementation do you use?


--

David Wood

unread,
Aug 5, 2014, 10:24:17 AM8/5/14
to swagger-sw...@googlegroups.com
Whatever jackson 2.2.0 (http://wiki.fasterxml.com/JacksonRelease20) provides. 

On Tuesday, August 5, 2014 10:05:16 AM UTC-4, Ron R wrote:
Which JAX-RS implementation do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Aug 5, 2014, 10:27:15 AM8/5/14
to swagger-sw...@googlegroups.com
Jackson is a JSON parser, it's not a JAX-RS implementation (nor does it bind itself to any specific implementation).
You have several dependencies that shouldn't necessarily be together. I'd suggest cleaning up that first and go from there.

To be clear, common JAX-RS implementations are Jersey, RestEasy, CXF and Wink.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

David Wood

unread,
Aug 5, 2014, 10:33:46 AM8/5/14
to swagger-sw...@googlegroups.com
Then it looks like the answer is JAX-RS 1.1, which is the version supported by Jersey 1.17.  Is that version supported by swagger?


On Tuesday, August 5, 2014 10:27:15 AM UTC-4, Ron R wrote:
Jackson is a JSON parser, it's not a JAX-RS implementation (nor does it bind itself to any specific implementation).
You have several dependencies that shouldn't necessarily be together. I'd suggest cleaning up that first and go from there.

To be clear, common JAX-RS implementations are Jersey, RestEasy, CXF and Wink.
On 5 August 2014 17:24, David Wood <davidw...@gmail.com> wrote:
Whatever jackson 2.2.0 (http://wiki.fasterxml.com/JacksonRelease20) provides. 

On Tuesday, August 5, 2014 10:05:16 AM UTC-4, Ron R wrote:
Which JAX-RS implementation do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Aug 5, 2014, 10:40:16 AM8/5/14
to swagger-sw...@googlegroups.com
Yes, it is most certainly supported.

I'd strongly advise on using maven, even if it does have some initial learning curve. Right now, looking at your dependencies, you pretty much threw in every possible jar and that can lead to conflicts.
The following jars (at least) should be removed:
/WPML-Service/WebContent/WEB-INF/lib/swagger-jersey2-jaxrs_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-oauth2-server_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-servlet_2.10-1.3.7.jar
/WPML-Service/WebContent/WEB-INF/lib/swagger-utils_2.10-1.3.7.jar

Once they are removed, please try again and check if it works.
If it doesn't, please provide details on how you configure Swagger (either by web.xml, code or both).


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

David Wood

unread,
Aug 5, 2014, 11:05:42 AM8/5/14
to swagger-sw...@googlegroups.com
Removed the suggested jars.  I also upgraded to Jersey 2.  But still no joy.

Swagger is configured via web.xml only with the following:

  <servlet>
  <servlet-name>JerseyJaxrsConfig</servlet-name>
  <servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
  <init-param>
    <param-name>api.version</param-name>
    <param-value>0.0.1</param-value>
  </init-param>
  <init-param>
    <param-name>swagger.api.basepath</param-name>
    <param-value>http://localhost:8080/WPML-Service/api</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>

David Wood

unread,
Aug 5, 2014, 11:41:32 AM8/5/14
to swagger-sw...@googlegroups.com
Sorry, my mistake there is a bit more the web.xml to configure swagger. Here is the complete listing. 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>WPML-Service</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
 
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.ibm.watson.pml.service,com.wordnik.swagger.jaxrs.listing</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

 
  <servlet>
  <servlet-name>JerseyJaxrsConfig</servlet-name>
  <servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
  <init-param>
    <param-name>api.version</param-name>
    <param-value>0.0.1</param-value>
  </init-param>
  <init-param>
    <param-name>swagger.api.basepath</param-name>
    <param-value>http://localhost:8080/WPML-Service/api</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>
 
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>

<listener>
  <listener-class>com.ibm.watson.pml.service.Initializer</listener-class>
</listener>

</web-app>

David Wood

unread,
Aug 5, 2014, 11:54:13 AM8/5/14
to swagger-sw...@googlegroups.com

The JSONPolicy object is input and seems to be working correctly in the swagger-ui, but does get "skipping class" at the end.  The JSONCreatePolicyResponse also shows "skipping class".  I've also tried make JSONCreatePolicyResponse not inherit from JSONStatus but no change.

11:42:18.816 [http-bio-8080-exec-7] DEBUG c.w.swagger.core.util.ModelUtil$ - adding dependent model com.ibm.watson.pml.service.policy.JSONPolicy
11:42:18.816 [http-bio-8080-exec-7] DEBUG c.w.swagger.core.util.ModelUtil$ - adding dependent model java.lang.String
11:42:18.816 [http-bio-8080-exec-7] DEBUG c.w.swagger.core.util.ModelUtil$ - adding dependent model com.ibm.watson.pml.service.policy.PolicyService$JSONPolicyIDList
11:42:18.844 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing class class com.ibm.watson.pml.service.policy.JSONPolicy
11:42:18.847 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.repID
11:42:18.851 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.851 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.851 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.853 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.853 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field repID
11:42:18.854 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.name
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field name
11:42:18.855 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.description
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field description
11:42:18.856 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.type
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field type
11:42:18.857 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.language
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field language
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing field public java.lang.String com.ibm.watson.pml.service.policy.JSONPolicy.policy
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 14 keys, got java.lang.String
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 14 keys, got string
11:42:18.858 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 14 keys, got string
11:42:18.859 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field policy
11:42:18.859 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing class class java.lang.Object
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - field name for method equals is equals
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - field name for method getClass is class
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native java.lang.Class java.lang.Object.getClass()
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting null
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - skipping class
...

11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing class class com.ibm.watson.pml.service.policy.JSONCreatePolicyResponse
11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing class class com.ibm.watson.pml.service.json.JSONStatus
11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing class class java.lang.Object
11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - field name for method equals is equals
11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - field name for method getClass is class
11:42:18.886 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native java.lang.Class java.lang.Object.getClass()
11:42:18.887 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - inspecting null
11:42:18.887 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - skipping class
11:42:18.860 [http-bio-8080-exec-7] DEBUG c.w.s.converter.ModelPropertyParser - skipping class

David Wood

unread,
Aug 5, 2014, 2:10:32 PM8/5/14
to swagger-sw...@googlegroups.com
SOLVED:  the problem appears to have been that the JSONCreatePolicyResponse did not have any public fields.  When I changed the (one) field to public the schema became visible in the UI. 
Reply all
Reply to author
Forward
0 new messages