{
"apiVersion":"1.0",
"apis":{"description":"",
"path":"/resources/samplehub/sample/insert"},
"basePath":"http://localhost:8080",
"swaggerVersion":"1.1"
}
The API Decl
{"apiVersion":"1.0","apis":{"description":"Inserts a sample and retruns a SAM_ID","operations":{"httpMethod":"GET","nickname":"insertSample","notes":"Validates and inserts the sample data","parameters":[{"allowMultiple":"false","dataType":"string","description":"Name of the inventory","name":"inventory_name","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"ID of the inventory lot","name":"inventory_lot_id","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"ID of the project","name":"project_id","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"Name of the lab","name":"lab","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"well ID","name":"well_id","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"Label of the sample","name":"label","paramType":"query","required":"false"},{"allowMultiple":"false","dataType":"string","description":"Unix ID of the user","name":"login","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"ID of the treatment","name":"treatment_id","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"string","description":"Sample preparation method","name":"sample_prep","paramType":"query","required":"false"},{"allowMultiple":"false","dataType":"string","description":"Sample extraction type","name":"extraction_type","paramType":"query","required":"true"},{"allowMultiple":"false","dataType":"float","description":"Concentration of the sample","name":"concentration","paramType":"query","required":"false"},{"allowMultiple":"false","dataType":"float","description":"Volume of the sample","name":"volume","paramType":"query","required":"false"},{"allowMultiple":"false","dataType":"string","description":"User comments","name":"comments","paramType":"query","required":"false"}],"responseClass":"sample_hub","summary":"Inserts a sample"},"path":"/samplehub/sample/insert"},"basePath":"http://localhost:8080","models":null,"resourcePath":"/samplehub/sample/insert","swaggerVersion":"1.1"}
Modified part of Swagger UI HTML file
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8080/SwaggerTest/resources",
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put'],
...
}
I'd appreciate your help.
Thanks,
Sahar
<web-app>
<display-name>Swagger Test Web Application</display-name>
<servlet>
<servlet-name>Bootstrap</servlet-name>
<servlet-class>com.genentech.bioinformatics.swaggertest.Bootstrap</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Jersey Web Application </servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.genentech.bioinformatics.swaggertest;com.wordnik.swagger.jaxrs.listing</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/SwaggerTest</param-value>
</init-param>
{"apiVersion":"1.0","apis":
{"description":"",
"path":"/resources/samplehub/sample/insert"},
Hi Sahar,
I swear the same issue has come up a million times, and I have yet to detect it right away. The issue is very simple--your JSON mapper isn't properly configured. You can see why like this.
if you look at your /resources, it looks like such:
{
"apiVersion": "1.0",
"apis": {
"description": "",
"path": "/resources/samplehub/sample/insert"
},
"basePath": "http://localhost:8080",
"swaggerVersion": "1.1"
}
the `apis` element is actually an array. You are hitting the dreadful "single-element array bug" that is built into most versions of Jersey (some say it's not a bug, but they probably haven't had to troubleshoot it much). If you were to add just another @Api resource, you'd see it turn into an array:
{
"apiVersion": "1.0",
"apis": [
{
"description": "",
"path": "/resources/samplehub/sample/insert"
},
{
"description": "",
"path": "/resources/samplehub/sample/somethingElse"
}
],
The same goes for your api declaration. Note the `parameters` are in an array, but the `apis` are not.
The solution is simple, configure Jackson to render the JSON like in this example:
And life will be good.
Side note--this is one of the issues addressed in the 1.3 release. We render the JSON ourselves so you don't have to monkey with your default JSON mapper. There's always the off chance that you want arrays with one element to be treated like this.
In the new version of swagger, yes:
the @Produces annotations are picked up and you'll get the appropriate drop-down in the response type:
http://petstore.swagger.wordnik.com/#!/pet/getPetById_get_0
In the one you're on, it's a bit more work.
Glad it's working!