loading...

Add openAPI document to your maven Spring-boot project

cuongld2 profile image cuongld2 ・1 min read

Alt Text
Photo by Lanju Fotografie on Unsplash

I.What is OpenAPI
OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including:

  • Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)
  • Operation parameters Input and output for each operation
  • Authentication methods
  • Contact information, license, terms of use and other information.

API specifications can be written in YAML or JSON. The format is easy to learn and readable to both humans and machines. The complete OpenAPI Specification can be found on GitHub: OpenAPI 3.0 Specification

You can find out more information about OpenAPI from here

By the end of this post, you should be able to see the API documentation like below:
Alt Text

II.OpenAPI documentation
What dependency we need to add to POM file

We also need to add some annotation to the controller api file

That’s it. Run the maven spring-boot project to see what happens

mvn spring-boot:run

You can navigate to the default url in your browser to check the documentation.

The full source code can be found in github from here.

Happy coding ~~

Posted on by:

cuongld2 profile

cuongld2

@cuongld2

Learning is hard work, but everything you learn is yours and will make subsequent learning easier. Medium page : https://medium.com/@ledinhcuong99

Discussion

pic
Editor guide