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.
My *web.xml* file contains (as per information obtained from
https://github.com/swagger-api/swagger-core/wiki/1.3--1.5-Migration )
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
<param-value>http://localhost:8080/Srest</param-value>
</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>).
If I call http://localhost:8080/rest/swagger.json, instead of seeing the
content of my swagger.json file, all I see returned is:
*{"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.
If I call http://localhost:8080/rest/swagger, a file is downloaded
containing the following (same content as above):
*---*
*swagger: "2.0"*
*info:*
* version: "1.0.0"*
* title: "RESTful Webservice"*
*host: "localhost:8080"*
*basePath: "/rest"*
*schemes:*
*- "http"*
If I try http://localhost:8080/rest/swagger/index.html, I just get a JBoss
404 error, "*JBWEB000124: The requested resource is not available.*".
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.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.