Ad Code

Ticker

6/recent/ticker-posts

SpringBoot - Design First Approach to Generate REST APIs Document Specification with OPENAPI and SWAGGER UI using external static openapi.yaml file in 7 simple steps

This example explains how SpringBoot application can expose its API description through an OpenAPI specification and how one can test it via a user-friendly UI named Swagger UI. 

In this example we are going to see how REST APIs Document Specification can be generated Using OPENAPI and SWAGGER UI from external static open-api-swagger.yaml file in just 7 Simple Steps.

Prerequisites To complete this example:

  • An IDE
  • JDK 11+ installed with JAVA_HOME configured appropriately
  • Apache Maven 3.8.1+

Here are the Steps:

1. Create a maven project using SpringBoot and add the below Dependencies in pom.xml



2.Create the static openapi file to serve which must be a valid document conforming to the OpenAPI specificationThe openapi file can be represented in yaml or json formats.

3. Here is our open-api-swagger.yaml file looks like



4. Place static OpenAPI document file under resources like below:


5. Create openApiSpecConfig configuration class. In this class by using implementation of bean SwaggerResourcesProvider , we can load the static yaml file from resources.



6. run the SpringBoot Application , Application will be Started Successfully and able to see the below console logs.





7. Open this URL http://localhost:8080/swagger-ui/ in browser, It will load the OpenApi Specification in swager-ui page.




So Just in 7 simple steps we have implemented  REST APIs Document Specification Using OPENAPI and SWAGGER UI from external static open-api-swagger.yaml file in Spring Boot Application.

GitHub Link : rajivksingh13/teachlea

Please feel free to provide your valuable comments, Thanks.

Post a Comment

0 Comments

Ad Code