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
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Springfox Swagger2

Springfox Swagger2 provides comprehensive Swagger 2 API documentation integration for Spring WebMVC and WebFlux applications. It automatically generates OpenAPI specifications from Spring controllers and models, offering seamless integration with Spring Boot through autoconfiguration.

Package Information

  • Package Name: springfox-swagger2
  • Package Type: maven
  • Language: Java
  • Group ID: io.springfox
  • Artifact ID: springfox-swagger2
  • Version: 2.10.5

Maven:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.10.5</version>
</dependency>

Gradle:

implementation 'io.springfox:springfox-swagger2:2.10.5'

Core Imports

import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;

Basic Usage

WebMVC Integration:

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

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
    // Configuration class automatically sets up Swagger 2 documentation
}

WebFlux Integration:

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

@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {
    // Configuration class automatically sets up Swagger 2 documentation
}

Architecture

Springfox Swagger2 is built around several key components:

  • Enable Annotations: Simple annotations to activate Swagger 2 documentation generation
  • Auto-Configuration: Spring Boot integration that automatically configures required beans and mappings
  • Documentation Mappers: Convert Springfox documentation models to Swagger 2 specification format
  • Web Controllers: Expose Swagger JSON documentation via REST endpoints
  • JSON Serialization: Custom Jackson module for proper Swagger 2 JSON formatting

Capabilities

Setup and Configuration

Easy activation of Swagger 2 documentation generation through Spring configuration annotations. Supports both WebMVC and WebFlux application types.

@EnableSwagger2WebMvc
public @interface EnableSwagger2WebMvc;

@EnableSwagger2WebFlux
public @interface EnableSwagger2WebFlux;

Configuration

API Documentation Generation

Core functionality that converts Spring application documentation into Swagger 2 specification format through comprehensive mapping capabilities.

public abstract class ServiceModelToSwagger2Mapper {
    public abstract Swagger mapDocumentation(Documentation from);
}

Documentation Generation

Web Integration

REST endpoints and controllers that serve generated Swagger 2 JSON documentation to clients and Swagger UI applications.

public class Swagger2ControllerWebMvc {
    public ResponseEntity<Json> getDocumentation(
        @RequestParam(value = "group", required = false) String swaggerGroup, 
        HttpServletRequest servletRequest
    );
}

public class Swagger2ControllerWebFlux {
    public ResponseEntity<Json> getDocumentation(
        @RequestParam(value = "group", required = false) String swaggerGroup, 
        ServerHttpRequest request
    );
}

Web Integration

JSON Serialization

Customized Jackson module for proper Swagger 2 JSON serialization with support for vendor extensions and example values.

public class Swagger2JacksonModule extends SimpleModule implements JacksonModuleRegistrar {
    public void maybeRegisterModule(ObjectMapper objectMapper);
    public void setupModule(SetupContext context);
}

JSON Serialization

Configuration Properties

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

Common Types

// Core Springfox types used throughout the API
interface Documentation {
    // Springfox documentation model
}

interface DocumentationCache {
    Documentation documentationByGroup(String groupName);
}

interface JsonSerializer {
    Json toJson(Object object);
}

// Swagger 2 model types
class Swagger {
    String getHost();
    String getBasePath();
    void host(String host);
    void basePath(String basePath);
}

class Json {
    // JSON wrapper for serialized Swagger documentation
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.springfox/springfox-swagger2@2.10.x
Publish Source
CLI
Badge
tessl/maven-io-springfox--springfox-swagger2 badge