So for CXF 2.7 I think swagger-core could work out of the box.

To be honest, I don’t know exactly what the internal integration CXF has with 
swagger-core provides, though I know they’ve worked on it to hook up nicely 
with CXF so it should be easier.

 

For swagger-core we have a sample that shows how to integrate it with a 
Spring-based CXF application - 
https://github.com/swagger-api/swagger-samples/tree/master/java/java-jaxrs-cxf 
but not one for Non-Spring one.

Based on your knowledge of other frameworks, you can look at the integrations 
with them and figure out what steps you need to take - 
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X.

In short, you need to:

1.       Add the dependencies (in your case, it would be swagger-jaxrs)

2.       Register these two classes as JAX-RS resources:

a.       io.swagger.jaxrs.listing.ApiListingResource

b.       io.swagger.jaxrs.listing.SwaggerSerializers

3.       Set up the basic configuration of Swagger-core based on one of the 
methods described in the wiki linked above.

 

Following that you’d need to add the various annotations to produce the 
documentation.

 

The second instruction (registering the resources) is enough to get at least a 
basic swagger.json output. It won’t describe anything without the annotations, 
but it should give you a sense that you hooked it up in your app properly.

Since it’s just a JAX-RS resource like the rest, it will be found at the 
context root you use for any other resource in your app.

 

If you’re having trouble getting to that point, provide more details as to what 
you’re trying to access.

 

 

 

 

From: <[email protected]> on behalf of Jeff Davis 
<[email protected]>
Reply-To: "[email protected]" 
<[email protected]>
Date: Thursday, 4 August 2016 at 14:15
To: Swagger <[email protected]>
Subject: Re: Can't Generate swagger.json With CXFNonSpringJaxrsServlet

 

Ron, 

 

I'm indifferent to what I'm using so long as I can generate the swagger.json.  
Is there something I can use other that Swagger2Feature?

On Thursday, August 4, 2016 at 3:10:21 PM UTC-6, Ron wrote: 

Hi Jeff,

 

Since you’re using the Swagger2Feature, you could get better support for it in 
the CXF mailing list as that’s their implementation for it.

 

 

 

From: <[email protected]> on behalf of Jeff Davis 
<[email protected]>
Reply-To: "[email protected]" <[email protected]>
Date: Thursday, 4 August 2016 at 13:47
To: Swagger <[email protected]>
Subject: Can't Generate swagger.json With CXFNonSpringJaxrsServlet

 

I am attempting to integrate swagger with a legacy REST service implemented 
using an older version of CXF.  I've attempted several configurations but can't 
get the swagger.json to generate.  Guidance on getting this resolved is greatly 
appreciated.  Please see project code below: 

 

HelloService.java

 

package swaggerRest;

import javax.ws.rs.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Path("/sample")
@Api(value = "/sample", description = "Sample REST for Swagger Testing")
public class HelloService {
 @GET
 @Path("hello")
 @ApiOperation(value = "Get hello message", response = String.class)
 public String sayHello(){
 return "Hello World";
 }
}

 

web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns="http://java.sun.com/xml/ns/javaee"; 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"; id="WebApp_ID" version="3.0">

  <display-name>swaggerRest</display-name>
  
  <context-param>
    <param-name>contextParam</param-name>
    <param-value>contextParamValue</param-value>
  </context-param>
  
  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
    <init-param>
      <param-name>jaxrs.serviceClasses</param-name>
      <param-value>swaggerRest.HelloService</param-value>
    </init-param>
    <init-param>
      <param-name>jaxrs.features</param-name>
      <param-value>org.apache.cxf.jaxrs.swagger.Swagger2Feature 
(basePath=/rest)</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

 

pom.xml

 

<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>swaggerRest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <dependencies>
    <!-- Apache CXF Dependencies -->
    <dependency>
         <groupId>org.apache.cxf</groupId>

      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-extension-providers</artifactId>
      <version>2.7.14</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description</artifactId>
      <version>3.1.7</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-jaxrs</artifactId>
      <version>1.1.1</version>
    </dependency>  
  
    <!-- SWAGGER -->
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-jaxrs</artifactId>
        <version>1.5.8</version>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.5.9</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>swagger-ui</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency> 
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
      <version>3.1.7</version>
    </dependency> 
  </dependencies>
 
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

 

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

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

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

Reply via email to