Versions Compared

Key

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

...

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

...

From Code

 

Code Block
java
java
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);

...

Code Block
xml
xml
<web-app>
    <context-param>
        <param-name>contextParam</param-name>
        <param-value>contextParamValue</param-value>
    </context-param>
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Servlet</display-name>
        <servlet-class>
              org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
        </servlet-class>
        <init-param>
            <param-name>jaxrs.serviceClasses</param-name>
            <param-value>
                           org.apache.cxf.systest.jaxrs.BookStore
            </param-value>
        </init-param>
        <init-param>
            <param-name>jaxrs.features</param-name>
            <param-value>
                        org.apache.cxf.jaxrs.swagger.Swagger2Feature
                        (basePath=/somepath)
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
</web-app>

New: Configuring from the properties file

Starting from CXF 3.1.13 and 3.2.0 it is possible to configure Swagger2Feature with a Properties file.

For example, while a samples/jax_rs/spring_boot demo configures the feature from the code, a  samples/jax_rs/spring_boot_scan demo has it configured from the properties file.

Default location for a properties file is "/swagger.properties". Swagger2Feature will pick it up if it is available, and the location can be overridden with a new Swagger2Feature 'swaggerPropertiesLocation' property. 

Note that the properties, if available, do not override the properties which may have been set as suggested above from the code or Spring/Blueprint contexts or web.xml. Instead they complement and serve as the default configuration properties: for example, if some properties have been set from the code then the values for the same properties found in the properties file will not be used.

Enabling in Spring Boot

See samples/jax_rs/spring_boot and on how to create Swagger2Feature in a @Bean method and samples/jax_rs/spring_boot_scan on how to auto-enable it.

...