Swagger 1.2 to 2.0 migration

514 views
Skip to first unread message

ssla...@gmail.com

unread,
Sep 10, 2015, 5:19:37 AM9/10/15
to Swagger
Using Java-CXF-Quickstart tutorial, I have managed to include swagger annotations into some of my classes. Everything works fine, I am even able to view the generated api locally in eclipse's web browser with swagger-ui.

Then I saw 1.3 to 1.5 Migration and Swagger-Core-RESTEasy-2.X-Project-Setup and I got my maven project to compile after following scraps from both guides (applying them for my project) and successfully completing the migration.

I have a Spring JaxRS CXF project.

Even though my project compiles and everything runs locally, I can't access the swagger.json where the guides say it is supposed to be. The UI in the eclipse browser returns 
400 : Error: HTTP 404 Not Found http://localhost:8081/jaxrs-service/api/swagger.json

I am aware of the schemes/host/basepath stuff with Swagger 2.0, and I have 
<security:intercept-url method="GET" pattern="/api/**"
 
access="IS_AUTHENTICATED_ANONYMOUSLY" />
this setup in my beans.xml file in the project. Still have no idea what I am doing wrong

Those are the dependencies in the pom.xml:

<dependency>
 
<exclusions>
 
<exclusion>
 
<artifactId>jsr311-api</artifactId>
 
<groupId>javax.ws.rs</groupId>
 
</exclusion>
 
</exclusions>
 
<groupId>io.swagger</groupId>
 
<artifactId>swagger-jaxrs</artifactId>
 
<version>1.5.0</version>
 
</dependency>

This is the plugin I use for swagger-ui (in the same pom.xml file):


<plugin>
 
<groupId>org.apache.maven.plugins</groupId>
 
<artifactId>maven-dependency-plugin</artifactId>
 
<version>2.8</version>
 
<executions>
 
<execution>
 
<id>unpack</id>
 
<phase>initialize</phase>
 
<goals>
 
<goal>unpack</goal>
 
</goals>
 
<configuration>
 
<artifactItems>
 
<artifactItem>
 
<groupId>com.wordnik</groupId>
 
<artifactId>swagger-ui</artifactId>
 
<version>2.0.18.ONTO</version>
 
<type>zip</type>
 
<outputDirectory>src\main\resources\dev\swagger</outputDirectory>
 
</artifactItem>
 
</artifactItems>
 
</configuration>
 
</execution>
 
</executions>
 
</plugin>


Another, non-related question:

<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
 
<property name="resourcePackage" value="xxxxxxxxxxxxxxxxxxxxx" />
 
<property name="version" value="1.3.6" />
 
<property name="schemes" value="http" />
 
<property name="host" value="localhost:8081" />
 
<property name="basePath" value="api" />
 
<property name="title" value=" API" />
 
<property name="description" value="Some sample text here, or something." />
 
<property name="contact" value="xxxxxxxxxxxxxxxxxxxxxxxxx" />
 
<property name="license" value="Apache 2.0 License" />
 
<property name="licenseUrl"
 
value="http://www.apache.org/licenses/LICENSE-2.0.html" />
 
<property name="scan" value="true" />
 
</bean>
Is it possible to add more than one resourcePackage property?
I have tried to simply add another tag, but it wasn't happy. Is there another syntax, or it's not possible?

Ron Ratovsky

unread,
Sep 10, 2015, 8:54:45 AM9/10/15
to Swagger
While can't be certain (not enough info), you should try accessing http://localhost:8081/jaxrs-service/swagger.json to see if you get the definition.

The swagger-ui version you use is too old and cannot be used with Swagger 2.0. We do not provide webjars as part of our solution.

The resourcePackage should be able to accept multiple comma-separated packages.

Hope this helps.

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

ssla...@gmail.com

unread,
Sep 10, 2015, 10:08:36 AM9/10/15
to Swagger
Hello Ron and thank you for the quick response.

I try accessing the exact same url that you posted,  http://localhost:8081/jaxrs-service/swagger.json
It still shows the 404 error mentioned above...

As far as the resourcePackage, I will try that later and post here how that goes.
I think the UI-thing will be put on hold for now since I am more suited with the 1.2 multiple JSONs rather than 2.0's single.

I am happy to provide additional info, just say what you need.

Ron Ratovsky

unread,
Sep 10, 2015, 10:15:12 AM9/10/15
to Swagger
swagger-core 1.5 produces Swagger 2.0, so if you're migrating to it you'll have a single JSON file.

Maybe if you share your full web.xml and applicationContext.xml, I could give you more help regarding where the swagger.json is hosted.
As an alternative, can you give me a sample API call URL you'd use?

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

ssla...@gmail.com

unread,
Sep 14, 2015, 3:00:39 AM9/14/15
to Swagger
Hello, sorry for the late response. I have tried the comma-separated package input but it doesn't detect it. Tried with '', " also with "," as separators, both failed to display anything. What is it that I'm missing?
Should I have each and every method annotated in the second package for it to work?

Ron Ratovsky

unread,
Sep 16, 2015, 10:33:16 AM9/16/15
to Swagger
Yup, it scans the annotations.

On Mon, Sep 14, 2015 at 10:00 AM, <ssla...@gmail.com> wrote:
Hello, sorry for the late response. I have tried the comma-separated package input but it doesn't detect it. Tried with '', " also with "," as separators, both failed to display anything. What is it that I'm missing?
Should I have each and every method annotated in the second package for it to work?

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