Properties from BeanConfig are not visible in swagger.json

379 views
Skip to first unread message

Octavian H

unread,
Feb 6, 2015, 5:05:50 AM2/6/15
to swagger-sw...@googlegroups.com
Hello,

I have created a maven project with Jersey 2.15 (without web.xml) and Swagger 1.5.0-M1. 
The generated war is deployed to Jetty 9.2.7.v20150116.
The Jersey resource can be accessed from http://127.0.0.1:8080/myapp/hello and the swagger.json is accessible from http://127.0.0.1:8080/myapp/swagger.json, but the content is based only on the annotations from the resource file. There is no information about license, title, description and most importantly the basePath. 
Because of this I cannot test any REST calls in swagger-ui (it tries to call http://127.0.0.1:8080/hello which obviously doesn't exist).

Can somebody help me with this?

Below is my code:

@ApplicationPath("myapp")
public class MyAppConfig extends ResourceConfig {
    private static Logger logger = Logger.getLogger(MyAppConfig.class.toString());

    public MyAppConfig() {
        // integration with Swagger
        packages("com.wordnik.swagger.jaxrs.json");
        packages("com.wordnik.swagger.jersey.listing");

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setBasePath("myapp");
        beanConfig.setVersion("1.0");

        Info info = new Info();
        info.setTitle("MyApp REST API");
        info.setDescription("blah blah");
        info.setVersion("1.0");

        License license = new License();
        license.setName("Apache License, Version 2.0");
        license.setUrl("http://www.apache.org/licenses/LICENSE-2.0.txt");
        info.setLicense(license);

        beanConfig.setInfo(info);
        beanConfig.setResourcePackage("com.myapp.web");
        beanConfig.setScan(true);

        register(MyAppResource.class);
register(MyAppCORSResponseFilter.class);
        // Register an instance of LoggingFilter.
        register(new LoggingFilter(logger, true));

        // Enable Tracing support.
        property(ServerProperties.TRACING, "ALL");
    }
}

Thanks,
Octavian

Ron Ratovsky

unread,
Feb 6, 2015, 5:09:54 AM2/6/15
to swagger-sw...@googlegroups.com
For now, you can use the SNAPSHOT version of 1.5.0 which contains the fix for the issue.


--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Octavian

unread,
Feb 6, 2015, 5:26:36 AM2/6/15
to swagger-sw...@googlegroups.com
Hello,

Thanks for the fast reply.

What I need to add in the pom.xml so as to use the SNAPSHOT version or I need to download the code from github and then build it locally?

Octavian

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/xJlJzkJtK-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron Ratovsky

unread,
Feb 6, 2015, 6:13:58 AM2/6/15
to swagger-sw...@googlegroups.com

You need to add sonatype's repository for it. I'm not on my computer so it's difficult for me to give you the address buy I'm sure a Google search will give you the info.

Octavian

unread,
Feb 6, 2015, 10:11:05 AM2/6/15
to swagger-sw...@googlegroups.com
Ok, I was able to use the SNAPSHOT by inserting the followings lines in pom.xml:

<repositories>
        <repository>
            <id>snapshots-repo</id>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

And I use the code from https://github.com/swagger-api/swagger-core/issues/855 for setting properties on BeanConfig object

@ApplicationPath("myapp")
public class MyAppConfig extends ResourceConfig {
    private static Logger logger = Logger.getLogger(MyAppConfig.class.toString());

    public MyAppConfig() {
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setBasePath("myapp");
        beanConfig.setVersion("1.0");
        beanConfig.setTitle("MyApp REST API");
        beanConfig.setDescription("blah blah");
        beanConfig.setLicense("Apache License, Version 2.0");
        beanConfig.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.txt");
        beanConfig.setResourcePackage("com.myapp.web");
        beanConfig.setScan(true);

        packages("com.wordnik.swagger.jaxrs.json");
        packages("com.wordnik.swagger.jersey.listing");

        register(MyAppResource.class);
register(MyAppCORSResponseFilter.class);
        // Register an instance of LoggingFilter.
        register(new LoggingFilter(logger, true));

        // Enable Tracing support.
        property(ServerProperties.TRACING, "ALL");
    }
}

License, title, description, version are shown in the swagger.json, but basePath not.
What I am doing wrong?

Octavian

Tony Tam

unread,
Feb 6, 2015, 10:34:43 AM2/6/15
to swagger-sw...@googlegroups.com
I'll look shortly to see where the value is going. I believe what you're doing is correct. 


tony tam

unread,
Feb 6, 2015, 11:35:41 AM2/6/15
to swagger-sw...@googlegroups.com
This has been fixed in https://github.com/swagger-api/swagger-core/issues/857

Please grab the latest 1.5.0-SNAPSHOT to pick up the changes.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

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



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/xJlJzkJtK-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

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

--
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.

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

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/xJlJzkJtK-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

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

--
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.
Reply all
Reply to author
Forward
0 new messages