Hi
I know this topic (or similar) seems to have been raised in many forums. I have tried so many different "solutions", but nothing is working for me. The scenario is that I have created a swagger.json file describing my RESTful API and using the "swagger-codegen-maven-plugin", I have generated the java code (maven setup below). This worked flawlessly.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/webapp/swagger.json</inputSpec>
<language>jaxrs-resteasy</language>
<output>${project.build.directory}/generated-sources</output>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<invokerPackage>za.co.company.ws.rest</invokerPackage>
<apiPackage>za.co.company.ws.rest.api</apiPackage>
<modelPackage>za.co.company.ws.rest.model</modelPackage>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
I also have the following dependencies:
- "swagger-jaxrs" v1.5.12
- "swagger-ui" v2.2.10 (I'm not sure if this necessary, but anyway)
I can build this code, deploy it in JBoss and access the endpoints with the auto-generated responses. PERFECT.
I would now like to view the Swagger UI docs for the API (i.e. like with the sample PetStore app). To use use swagger-ui, I have followed the installation method of copying the contents of the "dist" directory of the swagger-ui project into my project src/main/webapp/swagger directory, and modify the line in the index.html file "url = "
http://petstore.swagger.io/v2/swagger.json";" to reflect my own path to the swagger.json file (url = "
http://localhost:8080/rest/swagger.json";). My swagger.json resides in the src/main/webapp.
<?xml version="1.0" encoding="ISO-8859-1"?>
<display-name>RESTful Webservice</display-name>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>
io.swagger.jaxrs.listing.ApiListingResource,
io.swagger.jaxrs.listing.AcceptHeaderApiListingResource
</param-value>
</context-param>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>io.swagger.jaxrs.listing.SwaggerSerializers</param-value>
</context-param>
<servlet>
<servlet-name>DefaultJaxrsConfig</servlet-name>
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.title</param-name>
<param-value>RESTful Webservice</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>za.co.smartcall.ws.rest.api.ApiOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
With this configuration, I can call each endpoint of the generated rest service and get the default responses (under
http://localhost:8080/rest/<endpoint>).
{"swagger":"2.0","info":{"version":"1.0.0","title":"RESTful Webservice"},"host":"localhost:8080","basePath":"/rest","schemes":["http"]}
which is what is configured in the DefaultJaxrsConfig servlet in my web.xml.
---
swagger: "2.0"
info:
version: "1.0.0"
title: "RESTful Webservice"
host: "localhost:8080"
basePath: "/rest"
schemes:
- "http"
If I load the index.html file in my browser (src/main/webapp/swagger/index.html), I get a swagger-ui formatted page with no content from my swagger.json file.
I know I must be missing something simple, but it's damned hard to find :)
I would be immensely grateful for an assistance.