Implementing API Documentation

1. Implementing OpenAPI Annotations

Example: springdoc-openapi

@Operation(summary = "Place an order", description = "Creates an order from a cart")
@ApiResponses({
  @ApiResponse(responseCode = "201", description = "Created"),
  @ApiResponse(responseCode = "400", description = "Validation failed")
})
@PostMapping("/orders")
public OrderResponse place(@Valid @RequestBody CreateOrderRequest req) { ... }

2. Documenting Request/Response Examples

Example: @ExampleObject

@RequestBody(content = @Content(examples = {
  @ExampleObject(name = "minimal", value = "{\"customerId\":\"c_1\",\"lines\":[]}")
}))

3. Documenting Authentication

Example: Security scheme

@OpenAPIDefinition(security = @SecurityRequirement(name = "bearer"))
@SecurityScheme(name = "bearer", type = SecuritySchemeType.HTTP, scheme = "bearer", bearerFormat = "JWT")
public class OpenApiConfig {}

4. Documenting Schema Definitions

AnnotationPurpose
@Schema(description, example)Field-level docs
@Schema(required = true)Marks required
@Schema(allowableValues)Enum-like
@ArraySchemaList schemas

5. Documenting Error Responses

Example: Common error responses

@ApiResponse(responseCode = "401", description = "Unauthenticated",
  content = @Content(schema = @Schema(implementation = ProblemDetail.class)))
@ApiResponse(responseCode = "429", description = "Rate limited",
  headers = @Header(name = "Retry-After", schema = @Schema(type = "integer")))

6. Implementing Code Generation Configuration

ToolOutput
openapi-generatorClients in 50+ languages
swagger-codegenPredecessor, still used
orval / openapi-typescriptTS clients
Spring Cloud ContractStubs for testing

7. Using Documentation Annotations

AnnotationUse
@TagGroup endpoints
@ParameterParam description
@HiddenExclude from spec
@DeprecatedMarks deprecated DEPRECATED

8. Implementing Custom Documentation Generators

ToolApproach
Spring REST DocsTest-driven docs from passing tests
AsciiDoc + AsciidoctorLightweight markup → HTML/PDF
Custom pluginRead OpenAPI, render Markdown

9. Implementing Documentation Versioning

PracticeDetail
Per-version spec/v1/openapi.json, /v2/openapi.json
ChangelogDocument differences
Spec diff in CIopenapi-diff to detect breaking changes

10. Implementing Interactive Documentation

ToolDetail
Swagger UITry-it-out forms
RedocThree-pane layout
Stoplight ElementsModern UI
Postman CollectionsImportable from OpenAPI

11. Documenting API Rate Limits

Example: Rate-limit docs

Limit: 1000 requests / minute / API key
Headers returned:
  X-RateLimit-Limit:     1000
  X-RateLimit-Remaining: 998
  X-RateLimit-Reset:     1717000000
On exceed: 429 Too Many Requests with Retry-After (seconds)

12. Documenting Deprecation Notices

PlaceFormat
OpenAPI"deprecated": true per operation
Response headerDeprecation, Sunset
ChangelogDate, replacement, reason