Documentation Generator
Generate documentation for the code specified in $ARGUMENTS (a file, class, package, or method).
Step 1: Analyze the target
- Read the target code thoroughly.
- Identify what type of code it is: controller, service, repository, entity, DTO, configuration, utility, etc.
- Determine which documentation types are relevant.
Step 2: Ask the user what to generate
Present the applicable documentation options and ask the user to pick one or more:
- Javadoc — Add
/** */ documentation to classes, methods, and fields
- OpenAPI / Swagger — Add
@Operation, @ApiResponse, @Schema, @Tag annotations (for controllers and DTOs)
- ADR — Write an Architecture Decision Record for a design choice visible in the code
- README section — Generate a markdown section explaining the module/package purpose and usage
Javadoc rules
When generating Javadoc:
- Classes: describe responsibility, when to use, and thread safety if relevant.
- Public methods: describe what it does, not how. Document parameters, return value, and thrown exceptions.
- Skip the obvious — don't add Javadoc to simple getters/setters,
toString, equals, hashCode, or self-explanatory one-liner methods.
- Use
@param for each parameter with a meaningful description (not just repeating the name).
- Use
@return with what the value represents, not just the type.
- Use
@throws for each checked and notable unchecked exception with the condition that triggers it.
- Use
{@link ClassName#method} to reference related code.
- Use
{@code value} for inline code references.
- No filler — never write "This method does X" or "This class is a class that...". Start directly with the verb.
Example:
/**
* Finds a user by their unique identifier.
*
* @param id the user's unique identifier, must not be {@code null}
* @return the matching user
* @throws UserNotFoundException if no user exists with the given id
* @see UserRepository#findById(Long)
*/
public User findById(Long id) { ... }
OpenAPI / Swagger rules
When generating OpenAPI annotations:
@Tag on the controller class to group endpoints.
@Operation on each endpoint with summary (short) and description (detailed, optional).
@ApiResponse for each possible HTTP status code (200, 201, 400, 404, 500, etc.) with description and content schema.
@Parameter for path variables and query params with description, required, and example.
@Schema on DTO fields with description, example, and requiredMode where relevant.
- Use realistic
example values, not placeholders like "string" or "0".
Example:
@Tag(name = "Users", description = "User management operations")
@RestController
@RequestMapping("/api/v1/users")
public class UserController {
@Operation(summary = "Get user by ID")
@ApiResponse(responseCode = "200", description = "User found",
content = @Content(schema = @Schema(implementation = UserResponse.class)))
@ApiResponse(responseCode = "404", description = "User not found")
@GetMapping("/{id}")
public UserResponse getById(
@Parameter(description = "User ID", example = "42")
@PathVariable Long id) { ... }
}
For DTOs:
@Schema(description = "User creation request")
public record CreateUserRequest(
@Schema(description = "User's email address", example = "alice@example.com")
String email,
@Schema(description = "User's display name", example = "Alice Martin")
String name
) {}
ADR rules
When generating an Architecture Decision Record:
- Use the standard ADR format: Title, Status, Context, Decision, Consequences.
- Keep it factual and concise.
- Mention alternatives considered.
- Place in
docs/adr/ with a numbered filename (0001-use-jwt-for-authentication.md).
Template:
# [NUMBER]. [TITLE]
**Status:** Accepted | Proposed | Deprecated | Superseded by [ADR-XXXX]
## Context
What is the problem or situation that requires a decision?
## Decision
What is the chosen approach and why?
## Alternatives considered
- **Alternative A** — why it was rejected
- **Alternative B** — why it was rejected
## Consequences
- **Positive:** what improves
- **Negative:** what trade-offs or costs are introduced
General rules
- Read before writing — always understand the code before documenting it.
- Match existing style — if the project already has Javadoc or Swagger annotations, follow the same conventions.
- Don't over-document — documentation that restates the obvious adds noise, not clarity.
- Keep it maintainable — avoid documenting volatile implementation details that will drift out of sync.
1---2name: doc3description: Generate documentation for existing code — Javadoc, OpenAPI/Swagger annotations, Architecture Decision Records (ADRs), or README sections. Use when the user asks to document a class/method/endpoint, add API docs or Swagger annotations, write an ADR for a design decision, or produce a module/package README. French triggers: "documente cette classe", "ajoute la Javadoc", "génère la doc", "écris un ADR", "annotations Swagger/OpenAPI", "rédige le README". Code examples are Java/Spring, but ADR and README generation are language-agnostic.4---56# Documentation Generator78Generate documentation for the code specified in `$ARGUMENTS` (a file, class, package, or method).910## Step 1: Analyze the target11121. Read the target code thoroughly.132. Identify what type of code it is: controller, service, repository, entity, DTO, configuration, utility, etc.143. Determine which documentation types are relevant.1516## Step 2: Ask the user what to generate1718Present the applicable documentation options and ask the user to pick one or more:1920- **Javadoc** — Add `/** */` documentation to classes, methods, and fields21- **OpenAPI / Swagger** — Add `@Operation`, `@ApiResponse`, `@Schema`, `@Tag` annotations (for controllers and DTOs)22- **ADR** — Write an Architecture Decision Record for a design choice visible in the code23- **README section** — Generate a markdown section explaining the module/package purpose and usage2425## Javadoc rules2627When generating Javadoc:2829- **Classes**: describe responsibility, when to use, and thread safety if relevant.30- **Public methods**: describe what it does, not how. Document parameters, return value, and thrown exceptions.31- **Skip the obvious** — don't add Javadoc to simple getters/setters, `toString`, `equals`, `hashCode`, or self-explanatory one-liner methods.32- **Use `@param`** for each parameter with a meaningful description (not just repeating the name).33- **Use `@return`** with what the value represents, not just the type.34- **Use `@throws`** for each checked and notable unchecked exception with the condition that triggers it.35- **Use `{@link ClassName#method}`** to reference related code.36- **Use `{@code value}`** for inline code references.37- **No filler** — never write "This method does X" or "This class is a class that...". Start directly with the verb.3839Example:4041```java42/**43 * Finds a user by their unique identifier.44 *45 * @param id the user's unique identifier, must not be {@code null}46 * @return the matching user47 * @throws UserNotFoundException if no user exists with the given id48 * @see UserRepository#findById(Long)49 */50public User findById(Long id) { ... }51```5253## OpenAPI / Swagger rules5455When generating OpenAPI annotations:5657- **`@Tag`** on the controller class to group endpoints.58- **`@Operation`** on each endpoint with `summary` (short) and `description` (detailed, optional).59- **`@ApiResponse`** for each possible HTTP status code (200, 201, 400, 404, 500, etc.) with `description` and `content` schema.60- **`@Parameter`** for path variables and query params with `description`, `required`, and `example`.61- **`@Schema`** on DTO fields with `description`, `example`, and `requiredMode` where relevant.62- Use realistic `example` values, not placeholders like "string" or "0".6364Example:6566```java67@Tag(name = "Users", description = "User management operations")68@RestController69@RequestMapping("/api/v1/users")70public class UserController {7172 @Operation(summary = "Get user by ID")73 @ApiResponse(responseCode = "200", description = "User found",74 content = @Content(schema = @Schema(implementation = UserResponse.class)))75 @ApiResponse(responseCode = "404", description = "User not found")76 @GetMapping("/{id}")77 public UserResponse getById(78 @Parameter(description = "User ID", example = "42")79 @PathVariable Long id) { ... }80}81```8283For DTOs:8485```java86@Schema(description = "User creation request")87public record CreateUserRequest(88 @Schema(description = "User's email address", example = "alice@example.com")89 String email,9091 @Schema(description = "User's display name", example = "Alice Martin")92 String name93) {}94```9596## ADR rules9798When generating an Architecture Decision Record:99100- Use the standard ADR format: Title, Status, Context, Decision, Consequences.101- Keep it factual and concise.102- Mention alternatives considered.103- Place in `docs/adr/` with a numbered filename (`0001-use-jwt-for-authentication.md`).104105Template:106107```markdown108# [NUMBER]. [TITLE]109110**Status:** Accepted | Proposed | Deprecated | Superseded by [ADR-XXXX]111112## Context113What is the problem or situation that requires a decision?114115## Decision116What is the chosen approach and why?117118## Alternatives considered119- **Alternative A** — why it was rejected120- **Alternative B** — why it was rejected121122## Consequences123- **Positive:** what improves124- **Negative:** what trade-offs or costs are introduced125```126127## General rules128129- **Read before writing** — always understand the code before documenting it.130- **Match existing style** — if the project already has Javadoc or Swagger annotations, follow the same conventions.131- **Don't over-document** — documentation that restates the obvious adds noise, not clarity.132- **Keep it maintainable** — avoid documenting volatile implementation details that will drift out of sync.