Category: spring_boot
Documenting APIs with Swagger/OpenAPI
Published on 08 Jul 2026
Explanation
Swagger (OpenAPI) automatically generates interactive API documentation for Spring Boot REST APIs. It allows developers to explore and test endpoints directly from the browser.
Code:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
Explanation
After adding the dependency and starting the application, Swagger UI becomes available for testing APIs.
Code:
http://localhost:8080/swagger-ui/index.html
Explanation
The @Operation annotation is used to describe an API endpoint.
Code:
@Operation(summary="Get Student By Id")
@GetMapping("/{id}")
public Student getStudent(@PathVariable Long id){
return studentService.findById(id);
}
Explanation
The @Parameter annotation documents request parameters.
Code:
@GetMapping("/{id}")
public Student getStudent(
@Parameter(description="Student ID")
@PathVariable Long id){
return studentService.findById(id);
}
Explanation
Swagger UI displays all endpoints, request parameters, response schemas, and allows testing without Postman.
Code:
Open Browser: http://localhost:8080/swagger-ui/index.html