Hackforge Academy

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

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community