Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 58E7017BFE for ; Mon, 21 Sep 2015 10:48:15 +0000 (UTC) Received: (qmail 64815 invoked by uid 500); 21 Sep 2015 10:48:09 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 64757 invoked by uid 500); 21 Sep 2015 10:48:09 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 64748 invoked by uid 99); 21 Sep 2015 10:48:09 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2015 10:48:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 82F631A2839 for ; Mon, 21 Sep 2015 10:48:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.301 X-Spam-Level: **** X-Spam-Status: No, score=4.301 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RDNS_NONE=2.5, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id YC9WkuUv72EF for ; Mon, 21 Sep 2015 10:47:55 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (unknown [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id B5606204D2 for ; Mon, 21 Sep 2015 10:47:55 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 33CCEE046A for ; Mon, 21 Sep 2015 10:47:55 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 23C2D3A01E3 for ; Mon, 21 Sep 2015 10:47:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r966198 - in /websites/production/cxf/content: cache/docs.pageCache docs/swaggerfeature-swagger2feature.html Date: Mon, 21 Sep 2015 10:47:54 -0000 To: commits@cxf.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150921104755.23C2D3A01E3@svn01-us-west.apache.org> Author: buildbot Date: Mon Sep 21 10:47:51 2015 New Revision: 966198 Log: Production update by buildbot for cxf Added: websites/production/cxf/content/docs/swaggerfeature-swagger2feature.html Modified: websites/production/cxf/content/cache/docs.pageCache Modified: websites/production/cxf/content/cache/docs.pageCache ============================================================================== Binary files - no diff available. Added: websites/production/cxf/content/docs/swaggerfeature-swagger2feature.html ============================================================================== --- websites/production/cxf/content/docs/swaggerfeature-swagger2feature.html (added) +++ websites/production/cxf/content/docs/swaggerfeature-swagger2feature.html Mon Sep 21 10:47:51 2015 @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + +Apache CXF -- SwaggerFeature / Swagger2Feature + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
   + + + +
+ + + + + +
+ + + +
+
+
  
  + + + + + +
+ + + +
+

SwaggerFeature / Swagger2Feature

 

The CXF Swagger2Feature allows you to generate Swagger 2.0 documents from JAX-RS service endpoints with a simple configuration.

For generating Swagger 1.2 documents, you can use SwaggerFeature instead of Swagger2Feature.

These features can be configured programatically in Java or using Spring or Blueprint beans.

Properties

The following optional parameters can be configured in Swagger2Feature

Note some properties listed below are not available or used differently in SwaggerFeature, as the corresponding properties are used differently in Swagger 2.0 and Swagger 1.2 . Please refer to the corresponding Swagger documentation for more information.)

NameDescriptionDefault
basePaththe context root path+null
contactthe contact information+"users@cxf.apache.org"
descriptionthe description+"The Application"
filterClassa security filter+null
hostthe host and port+null
ignoreRoutesexcludes specific paths when scanning all resources (see scanAllResources)++null
licensethe license+"Apache 2.0 License"
licenceUrlthe license URL+"http://www.apache.org/licenses/LICENSE-2.0.html"
prettyPrintwhen generating swagger.json, pretty-print the json document+false
resourcePackagea list of comma separated package names where resources must be scanned+a list of service classes configured at the endpoint
runAsFilterruns the feature as a filterfalse
scangenerates the swagger documentation+true
scanAllResourcesscans all resources including non-annotated JAX-RS resources++false
schemesthe protocol schemes+null
termsOfServiceUrlthe terms of service URL+null
titlethe title+"Sample REST Application"
versionthe version+"1.0.0"

Note: those descriptions marked with + correspond to the properties defined in Swagger's BeanConfig, and those marked with ++ correspond to the properties defined in Swagger's ReaderConfig.

Configuring Programatically

 

+
import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
+...
+
+    Swagger2Feature feature = new Swagger2Feature();
+
+    // customize some of the properties
+    feature.setBasePath("/api");
+    	
+   	// add this feature to the endpoint (e.g., to ServerFactoryBean's features) 
+   	ServerFactoryBean sfb = new ServerFactoryBean();
+   	sfb.getFeatures().add(feature);
+

 

Configuring in Spring

 

+
<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
+       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+       xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+                           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
+                           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+    ... 
+    <!-- JAXRS providers -->
+    <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
+
+    <!-- Application resources -->
+    <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
+
+    <!-- CXF Swagger2Feature -->  
+    <bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
+        <!-- customize some of the properties -->
+        <property name="basePath" value="/app/swaggerSample"/>
+    </bean>
+
+    ...
+    <jaxrs:server id="sampleServer" address="/swaggerSample">
+        <jaxrs:serviceBeans>
+            <ref bean="sampleResource" />
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="jsonProvider" />
+        </jaxrs:providers>
+        <jaxrs:features>
+            <ref bean="swagger2Feature" />
+        </jaxrs:features>
+    </jaxrs:server>
+</beans>
+
+
+

 

Configuring in Blueprint

 

+
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://cxf.apache.org/blueprint/core"
+       xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+       xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+                           http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
+                           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd"> 
+    ...
+    <!-- JAXRS providers -->
+    <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
+ 
+    <!-- Application resources -->
+    <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
+
+
+    <!-- CXF Swagger2Feature -->  
+    <bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
+        <!-- customize some of the properties -->
+        <property name="basePath" value="/cxf/swaggerSample"/>
+    </bean>
+ 
+    ...
+    <jaxrs:server id="sampleServer" address="/swaggerSample">
+        <jaxrs:serviceBeans>
+            <ref component-id="sampleResource" />
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref component-id="jsonProvider" />
+        </jaxrs:providers>
+        <jaxrs:features>
+            <ref component-id="swagger2Feature" />
+        </jaxrs:features>
+    </jaxrs:server>
+</blueprint>
+ 
+

Samples

CXF's distribution contains the following samples.

 

+
+ +
+
 
   + +   
   
+ + + + + + +