Swagger.json file is not generated

2,992 views
Skip to first unread message

Sailaja

unread,
Dec 13, 2015, 12:30:47 PM12/13/15
to Swagger
Hi,
I'm new to swagger and I have implemented swagger 2.0 using jersey 1.x. I have followed steps mentioned in 

Below is my code snippet
web.xml :

<?xml version="1.0" encoding="UTF-8"?>

version="3.0">
<!--Specify the local deployment or openshift -->
<context-param>
<param-name>local-deployment</param-name>
<param-value>true</param-value>
</context-param>

<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet>
<servlet-name>Jersey Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.sw.protection.backend.rest;io.swagger.jaxrs.json,
                io.swagger.jaxrs.listing</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping> 

<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.basepath</param-name>
<param-value>http://localhost:8081/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
        <servlet-name>SwaggerBootstrap</servlet-name>
        <servlet-class>com.sw.protection.backend.rest.Bootstrap</servlet-class>
        <load-on-startup>3</load-on-startup>
    </servlet> 
</web-app>

Java file

  @GET
    @Path("/{userName}")
    @Produces({ MediaType.APPLICATION_JSON })
    @Consumes({ MediaType.APPLICATION_JSON })
    @ApiOperation(value = "Get specific admin", httpMethod = "GET", notes = "Fetch the admin user details", response = Response.class)
    @ApiResponses(value = { @ApiResponse(code = 200, message = "success") })
    public Response getAdmin(
   @ApiParam(value = "user_name of admin", required = true) @PathParam("userName") String userName) {
//AdminService adminService = AppContext.getInstance().getBean(AdminService.class);

try {

Project name is Test

swagger.json file is not generated under http://{localhost:8081}/Test and also not getting any error in console, everything processed properly.


Can you please help me what I missed or wrong?

Tony Tam

unread,
Dec 13, 2015, 12:46:33 PM12/13/15
to swagger-sw...@googlegroups.com
Try going here:


That is because of having jersey mounted at /api/*:

<servlet-mapping>
<servlet-name>Jersey Servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping> 
--
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.

Sailaja

unread,
Dec 13, 2015, 1:09:01 PM12/13/15
to Swagger
Hi tam,

I tried that way but no luck. I also looked into the webapps folder and  couldn't find api folder. 

Sailaja

unread,
Dec 13, 2015, 1:16:06 PM12/13/15
to Swagger
please let me know if you need any more details. I was not able to figure out the issue as it not showing any error in console.

im using tomcat 7, eclipse luna 
 

Ron Ratovsky

unread,
Dec 14, 2015, 7:57:45 PM12/14/15
to swagger-sw...@googlegroups.com
There is no /api folder, that’s a semantic location controlled by your app.
However, if you use tomcat, then it would be hosted under your app’s name by default.
http://localhost:8081/<app-name>/api/swagger.json

--

Sailaja

unread,
Dec 15, 2015, 12:10:51 PM12/15/15
to Swagger
Hi Ron,

I scanned entire webapps folder and couldn't find api folder. How can we make sure swagger annotations are processed properly. when I executed in tomcat 7 I got below console out put.  

Dec 15, 2015 1:50:49 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  io.swagger.jaxrs.json
  io.swagger.sample.resource
  io.swagger.jaxrs.listing
Dec 15, 2015 1:50:49 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class io.swagger.sample.resource.PetResource
  class io.swagger.jaxrs.listing.ApiListingResource
  class io.swagger.sample.resource.UserResource
  class io.swagger.sample.resource.PetStoreResource
Dec 15, 2015 1:50:49 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
  class io.swagger.jaxrs.json.JacksonJsonProvider
  class io.swagger.jaxrs.listing.SwaggerSerializers
Dec 15, 2015 1:50:49 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.13 06/29/2012 05:14 PM'
01:50:50,258 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
01:50:50,258 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
01:50:50,258 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/opt/isv/tomcat-7.0/grid/webapps/swagger-java-sample-app/WEB-INF/classes/logback.xml]
01:50:50,288 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
01:50:50,298 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
01:50:50,298 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
01:50:50,338 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
01:50:50,338 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
01:50:50,338 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
01:50:50,338 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [io.swagger] to DEBUG
01:50:50,338 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
01:50:50,338 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
01:50:50,338 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
01:50:50,338 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@16f4c3e - Registering current configuration as safe fallback point

Dec 15, 2015 1:50:50 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive C:\opt\isv\tomcat-7.0\grid\webapps\swagger-java-sample-app.war has finished in 5,272 ms



Ron Ratovsky

unread,
Dec 15, 2015, 4:32:32 PM12/15/15
to swagger-sw...@googlegroups.com
Are you able to access any API endpoint of your application?
If so, which URL do you use?

From: <swagger-sw...@googlegroups.com> on behalf of Sailaja <v.l.s...@gmail.com>
Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com>
Date: Tuesday, 15 December 2015 at 09:10
To: Swagger <swagger-sw...@googlegroups.com>
Subject: Re: Swagger.json file is not generated

Sailaja

unread,
Dec 16, 2015, 10:55:16 AM12/16/15
to Swagger
yes I was able to access endpoints and worked fine. Below is sample one tried


Also I tried  sample project from below sample swagger repo and not generating file

Sasikanth PVS

unread,
Jan 22, 2016, 6:22:00 PM1/22/16
to Swagger
I am also facing exact same problem.

I am using websphere liberty 8.5  with jaxrs 2.0

I have also followed
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5

I followed custom application approach instead of web.xml approach.

Here is my class 

@ApplicationPath("/v1/test")
public class MyRestApplicaiton extends Application{
   
    public MyRestApplicaiton () {
        BeanConfig beanConfig = new BeanConfig();
       
        beanConfig.setScan(true);
        beanConfig.setVersion("1.0");
        beanConfig.setTitle("MY REST Service");
        beanConfig.setBasePath("/api");
        beanConfig.setResourcePackage("myapp.api,myapp.api.types");
        beanConfig.setPrettyPrint(true);
        beanConfig.setLicenseUrl("");
        beanConfig.setContact("sasi...@gmai.com");
        beanConfig.setTermsOfServiceUrl("");
        beanConfig.setTermsOfServiceUrl("");
        beanConfig.setDescription("Some description");

    }

    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> resources = new HashSet<>();
        resources.add(QARestService.class);
       
        resources.add(io.swagger.jaxrs.listing.ApiListingResource.class);
        resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
        return resources;
    }
}


the endpoints defined in QAService are working fine as expected. But there is no swagger.json file generated any where.

I have decorated QAService  class with @Api

@Path("qa")
@Api
public class QARestService {

***
also @ApiOperation on a rest service operaiton.




During server startup  I see below messages.
[err] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[err] SLF4J: Defaulting to no-operation (NOP) logger implementation
[err] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.


my rest operations are working fine but I dont see swagger.json is generated anywhere under 'WebContent'

Ron Ratovsky

unread,
Jan 22, 2016, 6:30:39 PM1/22/16
to swagger-sw...@googlegroups.com
Which version of swagger-core do you use?

From: <swagger-sw...@googlegroups.com> on behalf of Sasikanth PVS <sasi...@gmail.com>
Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com>
Date: Friday, 22 January 2016 at 15:22
To: Swagger <swagger-sw...@googlegroups.com>
Subject: Re: Swagger.json file is not generated

Rene Muñiz

unread,
Jan 25, 2016, 2:51:07 PM1/25/16
to Swagger

Have you tried adding swagger (io.swagger.resources) to the list of resources for your app? I believe that is how you your app to serve the swagger.json. (https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5#using-a-servlet)
I usually add it first in the list.

beanConfig.setResourcePackage("io.swagger.resources,myapp.api,myapp.api.types");

-Rene


On Friday, January 22, 2016 at 4:22:00 PM UTC-7, Sasikanth PVS wrote:
I am also facing exact same problem.

I am using websphere liberty 8.5  with jaxrs 2.0

I have also followed
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5

I followed custom application approach instead of web.xml approach.

Here is my class 

@ApplicationPath("/v1/test")
public class MyRestApplicaiton extends Application{
   
    public MyRestApplicaiton () {
        BeanConfig beanConfig = new BeanConfig();
       
        beanConfig.setScan(true);
        beanConfig.setVersion("1.0");
        beanConfig.setTitle("MY REST Service");
        beanConfig.setBasePath("/api");
        beanConfig.setResourcePackage("myapp.api,myapp.api.types");
        beanConfig.setPrettyPrint(true);
        beanConfig.setLicenseUrl("");
        beanConfig.setContact("sasi.p...@gmai.com");
Reply all
Reply to author
Forward
0 new messages