springdoc-openapi

repository·main·Indexed 25 days ago

https://github.com/springdoc/springdoc-openapi

A Java library that automates the generation of OpenAPI 3 documentation for Spring Boot applications by inspecting application semantics at runtime. It supports Spring Boot 3.x Web MVC and WebFlux, providing integration with Swagger UI and customizable endpoints for OpenAPI JSON and YAML documentation. The library includes specialized support for Kotlin features such as inline classes, nullable properties, and coroutines.

Tokens
2.1K
Snippets
7
Records
18
Agent score
87%

What's inside springdoc-openapi

  1. Add API Information and Security documentation

    main

    The library scans Spring beans for @OpenAPIDefinition and @Info annotations to populate API metadata such as Title, version, license, security, servers, tags, and externalDocs.

    For optimal performance, it is recommended to declare @OpenAPIDefinition and @SecurityScheme annotations within a Spring-managed bean.

  2. Integrate springdoc-openapi with Spring Boot 3.x WebFlux and Swagger UI

    main

    For Spring Boot 3.x WebFlux applications requiring Swagger UI, add the springdoc-openapi-starter-webflux-ui dependency.

    By default:

    • Swagger UI (HTML) is available at: http://server:port/context-path/swagger-ui.html
    • OpenAPI JSON is available at: http://server:port/context-path/v3/api-docs
    • OpenAPI YAML is available at: http://server:port/context-path/v3/api-docs.yaml
    <dependency>
       <groupId>org.springdoc</groupId>
       <artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
       <version>last-release-version</version>
    </dependency>
  3. Report a bug in springdoc-openapi

    main

    When reporting a bug via GitHub issues, provide the following information to speed up diagnosis:

    • A detailed description of your context (the title alone is insufficient).
    • The version of Spring Boot you are using.
    • The specific modules and versions of springdoc-openapi being used.
    • The actual result vs. the expected result (provide the OpenAPI Description in .yml or .json format).
    • A Minimal, Reproducible Example (e.g., using a HelloController) that reproduces the problem.
  4. Configure Spring Security for springdoc-openapi in Spring Boot 3

    main

    In Spring Boot 3, when using a separate management port for Actuator, the springdoc endpoints (OpenAPI and Swagger UI) are served on the main application port. If Spring Security is enabled, you must explicitly permit access to these paths in your SecurityFilterChain configuration.

    @Bean
    SecurityFilterChain api(HttpSecurity http) throws Exception {
      http
        .authorizeHttpRequests(auth -> auth
          .requestMatchers(
            "/v3/api-docs/**",   
            "/v3/api-docs.yaml", 
            "/swagger-ui/**",
            "/swagger-ui.html"
          ).permitAll()
          .anyRequest().authenticated()
        );
      return http.build();
    }
  5. Integrate springdoc-openapi in Spring Boot 3.x without Swagger UI

    main

    If you only need the OpenAPI JSON/YAML documentation without the Swagger UI HTML interface, add the springdoc-openapi-starter-webmvc-api dependency.

    By default:

    • OpenAPI JSON is available at: http://server:port/context-path/v3/api-docs
    • OpenAPI YAML is available at: http://server:port/context-path/v3/api-docs.yaml
    <dependency>
       <groupId>org.springdoc</groupId>
       <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
       <version>last-release-version</version>
    </dependency>
  6. Configure Spring JavaFormat in IntelliJ IDEA

    main

    To ensure proper code formatting in IntelliJ IDEA, install the Spring JavaFormat plugin and import the project's code style configuration:

    1. Install the Plugin:

    • Download the latest IntelliJ IDEA plugin from Maven Central.
    • In IntelliJ, go to IntelliJ IDEA -> Preferences -> Plugins.
    • Select Install Plugin from Disk... and choose the downloaded .jar file.

    2. Import Code Style:

    • Go to IntelliJ IDEA -> Preferences -> Editor -> Code Style.
    • Select Import Scheme -> IntelliJ IDEA code style XML.
    • Select the .idea/codeStyles/codeStyleConfig.xml file from this repository.