I have a Spring Boot application where I use OpenAPI to document my API's. Everything works as expected except I'm not able to configure a custom info object of the v3/api-docs. This is my code:
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@OpenAPIDefinition
public class OpenApiConfig {
@Bean
public OpenAPI customOpenAPI() {
Info info = new Info()
.title("My project")
.version("5.4.23");
return new OpenAPI().info(info);
}
}
and the following maven dependency:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.13</version>
</dependency>
I thought this is all that was needed but my response when calling the v3/api-docs does not contain an info field:
{
openapi: "3.0.1"
paths: {,…}
servers: [{url: "localhost:8080"}]
}
What am I doing wrong and how can set the info globally? I did notice however that Springdoc automatically creates an GlobalOpenApiCustomizer? Could this have something to do with it and how to set the custom info object?
You can defining the bean programmatically and you don’t need @OpenAPIDefinition
@Configuration
public class OpenApiConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("My project")
.version("5.4.23")
.description("Custom API documentation"));
}
}