axim-restdoc-generator
npx skills add https://github.com/axim-one/gradle-restdoc-generator --skill axim-restdoc-generator
Agent 安装分布
Skill 文档
Axim Gradle RestDoc Generator
A Gradle plugin that auto-generates REST API documentation by scanning Spring Boot @RestController classes and their Javadoc comments.
Version: 2.0.7 Requirements: Java 17+, Gradle 7.0+, Spring Boot Repository: https://github.com/Axim-one/gradle-restdoc-generator
Installation
build.gradle (buildscript)
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.github.Axim-one:gradle-restdoc-generator:2.0.7'
}
}
apply plugin: 'gradle-restdoc-generator'
settings.gradle (Plugin DSL)
pluginManagement {
repositories {
maven { url 'https://jitpack.io' }
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'gradle-restdoc-generator') {
useModule("com.github.Axim-one:gradle-restdoc-generator:${requested.version}")
}
}
}
}
plugins {
id 'gradle-restdoc-generator' version '2.0.6'
}
Configuration DSL
restMetaGenerator {
// Required
documentPath = 'build/docs'
basePackage = 'com.example'
serviceId = 'my-service'
// Service info (optional)
serviceName = 'My Service'
apiServerUrl = 'https://api.example.com'
serviceVersion = 'v1.0'
introductionFile = 'docs/introduction.md'
// Error code / response class (optional)
errorCodeClass = 'com.example.exception.ErrorCode'
errorResponseClass = 'com.example.dto.ApiErrorResponse' // v2.0.5+
// Authentication â apiKey (optional, type='token' also works)
auth {
type = 'apiKey' // or 'token' (backward-compatible alias)
headerKey = 'Access-Token'
value = '{{accessToken}}'
in = 'header' // 'header' (default), 'query', 'cookie'
descriptionFile = 'docs/auth.md'
}
// Authentication â Bearer (v2.0.7+)
// auth {
// type = 'http'
// scheme = 'bearer'
// bearerFormat = 'JWT' // optional
// value = '{{accessToken}}'
// descriptionFile = 'docs/auth.md'
// }
// Authentication â Basic (v2.0.7+)
// auth {
// type = 'http'
// scheme = 'basic'
// value = '{{username}}:{{password}}'
// descriptionFile = 'docs/auth.md'
// }
// Common headers (optional)
header('X-Custom-Header', 'default-value', 'Header description')
// Postman environments (optional)
environment('DEV') {
variable('base_url', 'https://dev.api.example.com')
variable('token', 'dev-token')
}
environment('PROD') {
variable('base_url', 'https://api.example.com')
variable('token', '')
}
// Postman sync (optional)
postmanApiKey = ''
postmanWorkSpaceId = ''
debug = false
}
DSL Property Reference
| Property | Required | Default | Description |
|---|---|---|---|
documentPath |
Yes | â | Output directory (relative to project root) |
basePackage |
Yes | â | Package(s) to scan (comma-separated for multiple) |
serviceId |
Yes | â | Service unique ID (used as JSON filename) |
serviceName |
No | "" |
Display name (OpenAPI title) |
apiServerUrl |
No | "" |
API base URL (OpenAPI servers) |
serviceVersion |
No | "v1.0" |
API version (OpenAPI version) |
introductionFile |
No | "" |
Markdown file path for service description |
errorCodeClass |
No | "" |
ErrorCode class FQCN (fallback: framework default) |
errorResponseClass |
No | "" |
Error Response DTO FQCN (v2.0.5+, fallback: ApiError) |
postmanApiKey |
No | "" |
Postman API Key (empty = skip sync) |
postmanWorkSpaceId |
No | "" |
Postman Workspace ID |
debug |
Yes | false |
Enable debug logging |
Auth DSL Properties (v2.0.7+)
| Property | Default | Description |
|---|---|---|
type |
"" |
Auth type: "token"/"apiKey" (API key) or "http" (Bearer/Basic) |
headerKey |
"" |
Header/parameter name (apiKey type only) |
value |
"" |
Auth value (token, "user:pass" for basic) |
descriptionFile |
"" |
Markdown file path for auth description |
in |
"header" |
apiKey location: "header", "query", "cookie" |
scheme |
"" |
HTTP auth scheme: "bearer", "basic" (http type only) |
bearerFormat |
"" |
Token format hint, e.g. "JWT" (bearer only) |
Javadoc Tags
Write Javadoc on controller methods to enrich the generated documentation:
/**
* ì¬ì©ì ì 보를 ì¡°íí©ëë¤.
*
* @param userId ì¬ì©ì ID
* @return ì¬ì©ì ì ë³´
* @response 200 ì±ê³µ
* @response 404 ì¬ì©ì를 ì°¾ì ì ìì
* @group ì¬ì©ì ê´ë¦¬
* @auth true
* @header X-Request-Id ìì² ì¶ì ID
* @error UserNotFoundException
*/
@GetMapping("/users/{userId}")
public UserDto getUser(@PathVariable Long userId) { ... }
Tag Reference
| Tag | Description |
|---|---|
@param |
Parameter description |
@return |
Return value description |
@response {code} {desc} |
HTTP response status code and description |
@error {ExceptionClass} |
Link error group â auto-populates errors and responseStatus |
@throws {ExceptionClass} |
Same as @error (standard Javadoc tag) |
@group |
API group name (maps to Postman folder) |
@auth true |
Mark endpoint as requiring authentication |
@header {name} {desc} |
Document a custom header |
@className |
Override generated class name |
NOTE: Method signature throws clauses are also auto-detected and linked to error groups (no Javadoc tag needed).
Error Code Documentation
Exception classes with public static final ErrorCode fields are auto-scanned:
public class UserNotFoundException extends RuntimeException {
public static final ErrorCode USER_NOT_FOUND =
new ErrorCode("USER_001", "error.user.notfound");
public static final ErrorCode USER_DELETED =
new ErrorCode("USER_002", "error.user.deleted");
public UserNotFoundException(ErrorCode errorCode) {
super(HttpStatus.NOT_FOUND, errorCode);
}
}
Error Code/Response Class Resolution (2-level priority)
- DSL explicit â
errorCodeClass/errorResponseClassin build.gradle - Framework default â
one.axim.framework.rest.exception.ErrorCode/one.axim.framework.rest.model.ApiError
Linking Errors to APIs
Use @error / @throws Javadoc tags or method throws clause:
/**
* ì¬ì©ì ìì¸ ì¡°í
* @error UserNotFoundException
*/
@GetMapping("/users/{id}")
public UserDto getUser(@PathVariable Long id) { ... }
// Or: auto-detected from throws clause
@GetMapping("/users/{id}/status")
public UserStatus getUserStatus(@PathVariable Long id) throws AuthException { ... }
Pagination Support
Spring Data Pageable/Page<T> are auto-recognized:
@GetMapping(name = "ì¬ì©ì íì´ì§ ì¡°í", value = "/paged")
public Page<UserDto> getUsers(Pageable pageable) { ... }
Auto-generated:
- Query params:
page(default: 0),size(default: 20),sort - Response model:
content,totalElements,totalPages,size,number,numberOfElements,first,last,empty,sort - API JSON:
isPaging: true,pagingType: "spring"
ApiResult Wrapper Unwrapping
ApiResult<T> wrapper types are auto-unwrapped:
// Single â returnClass: "UserDto"
public ApiResult<UserDto> getUser() { ... }
// List â returnClass: "UserDto", isArrayReturn: true
public ApiResult<List<UserDto>> getUsers() { ... }
// Paging â returnClass: "UserDto", isPaging: true, pagingType: "spring"
public ApiResult<Page<UserDto>> getUsersPaged(Pageable pageable) { ... }
Running the Plugin
./gradlew restMetaGenerator
Output Structure
build/docs/
âââ {serviceId}.json # Service definition
âââ openapi.json # OpenAPI 3.0.3 spec
âââ spec-bundle.json # Integrated bundle (service + APIs + models + errors)
âââ api/
â âââ {ControllerName}.json # Per-controller API definitions
âââ model/
â âââ {ClassName}.json # Model/DTO definitions
âââ error/
âââ errors.json # Error code groups
âââ error-response.json # Error response model structure
spec-bundle.json Structure
The bundle JSON combines all outputs into a single file for UI consumption:
{
"service": {
"serviceId": "my-service",
"name": "My Service",
"apiServerUrl": "https://api.example.com",
"version": "v1.0",
"introduction": "...",
"auth": { "type": "token", "headerKey": "Authorization", ... },
"headers": [...]
},
"apis": [
{
"id": "getUser",
"name": "ì¬ì©ì ì¡°í",
"method": "GET",
"urlMapping": "/users/{id}",
"returnClass": "com.example.dto.UserDto",
"parameters": [...],
"responseStatus": { "200": "ì±ê³µ", "404": "ì¬ì©ì를 ì°¾ì ì ìì" },
"errors": [{ "exception": "UserNotFoundException", "status": 404, "codes": [...] }]
}
],
"models": {
"com.example.dto.UserDto": {
"name": "UserDto",
"type": "Object",
"fields": [{ "name": "id", "type": "Long" }, ...]
}
},
"errors": [
{
"group": "User Not Found",
"exception": "UserNotFoundException",
"status": 404,
"codes": [{ "code": "USER_001", "name": "USER_NOT_FOUND", "message": "..." }]
}
],
"errorResponse": {
"name": "ApiErrorResponse",
"type": "Object",
"fields": [...]
}
}
Execution Pipeline
The restMetaGenerator task runs in this order:
- Error Code Scan â Collect ErrorCode fields from Exception classes
- API Document Generation â Scan
@RestControllerâ generate per-controller/model JSON - Error JSON Write â Output
errors.json+error-response.json - OpenAPI Spec â Generate
openapi.json(OpenAPI 3.0.3) - Spec Bundle â Generate
spec-bundle.json - Postman Sync â Sync Collection/Environment (if configured)
Changelog
- v2.0.7 â Auth DSL extension:
apiKey/http(Bearer/Basic) support for OpenAPI securitySchemes and Postman auth - v2.0.6 â Fixed empty version causing
//path, fixed ArrayIndexOutOfBoundsException for path-less mappings - v2.0.5 â Added
errorResponseClassDSL property - v2.0.4 â OpenAPI 3.0.3, spec-bundle.json, error code scanning, @error/@throws tags
- v2.0.3 â Fixed inner class enum ClassNotFoundException
- v2.0.2 â Spring Pageable/Page recognition, ApiResult unwrapping