How do you document a Spring Boot REST API with OpenAPI/Swagger? स्प्रिंग बूट REST API को OpenAPI/Swagger से कैसे डॉक्यूमेंट करें?
Spring Boot REST APIs are documented using springdoc-openapi (the modern successor to SpringFox), which scans controllers and generates an OpenAPI 3 specification automatically, along with an interactive Swagger UI page for testing endpoints in the browser.
Adding the springdoc-openapi-starter-webmvc-ui dependency is enough to get a working /swagger-ui.html page with zero configuration; annotations like @Operation, @Parameter, and @ApiResponse are then added to controller methods to enrich the generated docs with descriptions and example responses.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
@Operation(summary = "Get a user by ID")
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) { ... }स्प्रिंग बूट REST API को डॉक्यूमेंट करने के लिए springdoc-openapi का उपयोग होता है, जो कंट्रोलर्स को स्कैन करके स्वचालित रूप से OpenAPI 3 स्पेसिफिकेशन जनरेट करता है, साथ ही ब्राउज़र में एंडपॉइंट्स टेस्ट करने के लिए इंटरैक्टिव Swagger UI पेज भी देता है।
springdoc-openapi-starter-webmvc-ui डिपेंडेंसी जोड़ना बिना किसी कॉन्फिगरेशन के /swagger-ui.html पेज पाने के लिए काफी है; @Operation, @Parameter जैसे एनोटेशन को कंट्रोलर मेथड्स पर जोड़कर जनरेट किए गए डॉक्स को समृद्ध किया जाता है।
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
@Operation(summary = "Get a user by ID")
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) { ... }Was this answer clear?