CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-springfox--springfox-swagger2

Swagger 2 API documentation integration library for Spring WebMVC and WebFlux applications

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration

Setup and configuration capabilities for enabling Swagger 2 documentation generation in Spring applications. Provides simple annotations and auto-configuration for both WebMVC and WebFlux application types.

Capabilities

@EnableSwagger2WebMvc

Enables Swagger 2 support for Spring WebMVC applications. This annotation imports the necessary configuration for servlet-based Spring applications.

/**
 * Indicates that Swagger support should be enabled for WebMVC applications.
 * Must be applied to a Spring configuration class with @Configuration annotation.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import({Swagger2DocumentationWebMvcConfiguration.class})
@ConditionalOnWebApplication
public @interface EnableSwagger2WebMvc {
}

Usage Example:

import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
    // Additional Docket beans can be defined here
}

@EnableSwagger2WebFlux

Enables Swagger 2 support for Spring WebFlux reactive applications. This annotation imports the necessary configuration for reactive web applications.

/**
 * Indicates that Swagger support should be enabled for WebFlux applications.
 * Must be applied to a Spring configuration class with @Configuration annotation.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import({Swagger2DocumentationWebFluxConfiguration.class})
public @interface EnableSwagger2WebFlux {
}

Usage Example:

import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;

@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {
    // Additional Docket beans can be defined here
}

Swagger2DocumentationWebMvcConfiguration

Spring configuration class that provides the necessary beans for WebMVC Swagger 2 integration.

/**
 * Auto-configuration class for WebMVC Swagger 2 integration
 */
@Configuration
@ConditionalOnClass(name = "springfox.documentation.spring.web.SpringfoxWebMvcConfiguration")
@Import({ SpringfoxWebConfiguration.class, SpringfoxWebMvcConfiguration.class, SwaggerCommonConfiguration.class })
@ComponentScan(basePackages = {
    "springfox.documentation.swagger2.readers.parameter",
    "springfox.documentation.swagger2.mappers"
})
public class Swagger2DocumentationWebMvcConfiguration {
    
    /**
     * Provides Jackson module for Swagger 2 JSON serialization
     */
    public JacksonModuleRegistrar swagger2Module();
    
    /**
     * Creates handler mapping for Swagger 2 controller
     * @param environment Spring environment for property resolution
     * @param documentationCache Cache for documentation access
     * @param mapper Mapper for converting documentation to Swagger format
     * @param jsonSerializer JSON serializer for Swagger objects
     * @return Handler mapping for Swagger endpoints
     */
    public HandlerMapping swagger2ControllerMapping(
        Environment environment,
        DocumentationCache documentationCache,
        ServiceModelToSwagger2Mapper mapper,
        JsonSerializer jsonSerializer
    );
}

Swagger2DocumentationWebFluxConfiguration

Spring configuration class that provides the necessary beans for WebFlux Swagger 2 integration.

/**
 * Auto-configuration class for WebFlux Swagger 2 integration
 */
@Configuration
@ConditionalOnClass(name = "org.springframework.web.reactive.BindingContext")
@Import({ SpringfoxWebConfiguration.class, SpringfoxWebFluxConfiguration.class, SwaggerCommonConfiguration.class,
        Swagger2ControllerWebFlux.class })
@ComponentScan(basePackages = {
    "springfox.documentation.swagger2.readers.parameter",
    "springfox.documentation.swagger2.mappers"
})
public class Swagger2DocumentationWebFluxConfiguration {
    
    /**
     * Provides Jackson module for Swagger 2 JSON serialization
     */
    public JacksonModuleRegistrar swagger2Module();
}

Configuration Properties

The following properties can be used to customize Swagger 2 behavior:

  • springfox.documentation.swagger.v2.host - Override the hostname in generated Swagger specification
  • springfox.documentation.swagger.v2.path - Custom path for the API documentation endpoint (default: /v2/api-docs)

Example application.properties:

# Override hostname in Swagger spec
springfox.documentation.swagger.v2.host=api.example.com

# Custom API docs endpoint path
springfox.documentation.swagger.v2.path=/api/swagger.json

Component Scanning

Both configuration classes automatically scan for components in these packages:

  • springfox.documentation.swagger2.readers.parameter - Parameter readers and processors
  • springfox.documentation.swagger2.mappers - Object mappers for Swagger 2 conversion

Dependencies

These configuration classes require the following dependencies to be on the classpath:

  • Spring Boot Autoconfigure
  • Springfox core libraries (springfox-spring-web, springfox-swagger-common)
  • Jackson for JSON processing
  • Swagger 2 models (io.swagger.models)

WebMVC specific:

  • Spring Web MVC framework
  • Servlet API

WebFlux specific:

  • Spring WebFlux framework
  • Reactive streams API

Install with Tessl CLI

npx tessl i tessl/maven-io-springfox--springfox-swagger2

docs

configuration.md

documentation-generation.md

index.md

json-serialization.md

web-integration.md

tile.json