Using the Swagger UI
The Swagger UI is a web-based interface that provides interactive documentation for APIs. It allows developers to visualize and execute API endpoints, making it easier to understand and experiment with the API.
Before accessing the Swagger UI, let’s add one more annotation from Swagger: the OpenAPI
annotation. This contains some metadata from our API. We can do that in Spring by defining the OpenAPI
bean:
@Configuration
public class SpringDocConfiguration {
@Bean
OpenAPI apiInfo(
@Value("${application.version}") String version) {
return new OpenAPI().info(
new Info()
.title("Product Catalogue API")
.description("API for managing product catalog")
.version(version));
}
}
In this code, we use the OpenAPI
bean from Swagger to define metadata information. Specifically, we set the title, description, and version of the API. The version information is retrieved from the application...