Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Swagger2Feature

Table of Contents

...

Properties

The CXF Swagger2Feature allows you to generate Swagger 2.0 (http://swagger.io/specification/) documents from JAX-RS service endpoints with a simple configuration.

...

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"
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 + in the description field correspond to the properties defined in Swagger's BeanConfig, and those marked with ++ correspond to to the properties defined in Swagger's ReaderConfig.

Configuring Programatically

...

Code Block
xml
xml
<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>

...