Swagger UI - Yash-777/MyWorld GitHub Wiki
Swagger UI allows anyone β be it your development team or your end consumers β to visualize and interact with the APIβs resources without having any of the implementation logic in place. Itβs automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.
- Browser support: Swagger UI works in the latest versions of Chrome, Safari, Firefox, and Edge.
- Basic Structure
Swagger Dependency: If not already present
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>Global Swagger Configuration (Optional Enhancements)
You can keep a minimal configuration β grouping now happens automatically based on @Tag.
/**
* Swagger Configuration β Auto-grouped using @Tag annotations.
*
* β
No need to define multiple GroupedOpenApi beans.
* β
Each @Tag(name="...") creates a separate Swagger section automatically.
*/
@OpenAPIDefinition(
info = @Info(
title = "My World API",
version = "1.0",
description = "API documentation grouped by module and feature using @Tag annotations."
)
)
@Configuration
public class SwaggerConfig {
}π http://localhost:8080/myworld/swagger-ui.html
swagger ui to club some endpoints into a group & create multi-level grouping using java:
π§± Swagger UI display Structure: π§© GOAL - You want to automatically group endpoints in Swagger UI like:
User Module
ββ Users
ββ Authentication
Product Module
ββ Products
ββ Categories
π§± Directory Structure for Controllers
Organize your controllers by module:
src/main/java/com/myworld/controller/
βββ user/
β βββ UserController.java β /api/users/**
β βββ AuthController.java β /api/auth/**
βββ product/
βββ ProductController.java β /api/products/**
βββ CategoryController.java β /api/categories/**π§ By using @Tag annotations on your controllers. πͺ Optional: Add "Module" prefix for hierarchical feel.
You can create visual hierarchy (multi-level look) just by naming convention:
@Tag(name = "User Module - Users", description = "Manage users")
@Tag(name = "User Module - Authentication", description = "Login & signup APIs")
@Tag(name = "Product Module - Products", description = "Product operations")
@Tag(name = "Product Module - Categories", description = "Category operations")Prefix Tag Names (Recommended Visual Grouping)
Only visually nested (not technically)
@Tag(name = "Online Module: XML", description = "XML Validator API")
@RestController
@RequestMapping("/xml")
public class XmlValidatorController { }
@Tag(name = "Online Module: JSON", description = "JSON Validator API")
@RestController
@RequestMapping("/json")
public class JsonValidatorController { }
@Tag(name = "Online Module: Text", description = "Text Validator API")
@RestController
@RequestMapping("/text")
public class TextAnalysisController { }Result in Swagger UI
Online Module: JSON
Online Module: Text
Online Module: XML
You can use colon (:), dash (-), or arrow (β) for consistent look.
One shared tag on each controller
You just make sure all controllers share the same @Tag name and description, e.g.:
@Tag(name = "Online Module", description = "Online Module APIs for JSON, XML, Text")
@RestController
@RequestMapping("/json")
public class JsonValidatorController {
// JSON APIs here
}
@Tag(name = "Online Module", description = "Online Module APIs for JSON, XML, Text")
@RestController
@RequestMapping("/text")
public class TextAnalysisController {
// Text APIs here
}
@Tag(name = "Online Module", description = "Online Module APIs for JSON, XML, Text")
@RestController
@RequestMapping("/xml")
public class XmlValidatorController {
// XML APIs here
}Result:
In Swagger/OpenAPI UI, these 3 controllers will be grouped under one tag called "Online Module".
Online Module
βββ XML
βββ JSON
βββ Text
| ReadyAPI | Request Editor Interface |
|---|---|
| ReadyAPI allows teams to create, manage, and execute automated functional, security, and performance tests in one centralized interface β accelerating API quality for Agile and DevOps software teams. | ![]() |
