CR Sardar
CR Sardar

Reputation: 1018

springdoc-openapi-ui swagger 3 change API description

I am new to String and Swagger 3. How can I change the default API description i.e. OpenAPI definition in Swagger springdoc-openapi-ui swagger 3

enter image description here

Also version, developer information..

I am using

implementation "org.springframework.boot:spring-boot-starter-web:2.6.6"
implementation "org.springdoc:springdoc-openapi-ui:1.6.8"

In search, I see only they are showing default Swagger UI

Upvotes: 13

Views: 15121

Answers (2)

Tohid Makari
Tohid Makari

Reputation: 2484

Simply use following annotations :

In application launcher class(Configuration class):

@OpenAPIDefinition(info=@Info(title="Name of project"))

In Controller imports should be as follows :

import io.swagger.v3.oas.annotations.*

Calss level:

@OpenAPIDefinition()

Or

@Tag(name = "", description = "")
public class ApiController {

Method level :

@PutMapping(value = "/test")
@Operation(summary = "info...")
@ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "successfully updated"),
        @ApiResponse(responseCode = "400", description = "Bad request"),
        @ApiResponse(responseCode = "500", description = "Internal Server Error")})

And config class should be like this :

@Configuration
public class ApiDocumentationConfig {

    @Bean
    public OpenAPI apiDocConfig() {
        return new OpenAPI()
                .info(new Info()
                        .title("example API")
                        .description("example API for routing ")
                        .version("0.0.1")
                        .contact(new Contact()
                                .name("example")
                                .email("[email protected]")))
                .externalDocs(new ExternalDocumentation()
                        .description("Documentation")
                        .url("https:/wiki...."));
    }

    @Bean
    public MvcConfig mvcConfig() {
        return new MvcConfig();
    }

Upvotes: 20

Edi
Edi

Reputation: 2301

For standard Version I used:

@Bean
    public OpenAPI customOpenAPI() {
        final String locUrl = "http://localhost:8080";
        final String devUrl = "https://.de";
        final String testUrl = "https://.de";
        final String preUrl = "https://.de";
        final String proUrl = "https://.grp";

        return new OpenAPI().addServersItem(new Server().url(locUrl)).addServersItem(new Server().url(
                devUrl)).addServersItem(new Server().url(testUrl)).addServersItem(new Server().url(preUrl))
            .addServersItem(new Server().url(proUrl)).info(
                new Info().version("v1").title("XApp application API")
                    .description("(NOTE: If having Swagger UI issues w/ Chrome then use Firefox instead.)")
            .contact(new Contact().name("Edi")));
    }

and to change based on grouping I did:

@Profile("!dev")
    @Bean
    public GroupedOpenApi groupedPublicOpenApi10() {
        return GroupedOpenApi
            .builder()
            .addOpenApiCustomiser(openApi -> openApi.getInfo().setVersion("v1"))
            .group("API-v1")
            .pathsToMatch("/api/**")
            .displayName("API v1")
            .build();
    }

Upvotes: 1

Related Questions