home / skills / hoangnguyen0403 / agent-skills-standard / api-design
This skill helps you design Spring Boot APIs with OpenAPI, URI versioning, and robust RFC 7807 error handling.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill api-designReview the files below or copy the command above to add this skill to your agents.
---
name: Spring Boot API Design
description: Standards for OpenAPI, Versioning, and Global Error Handling
metadata:
labels: [spring-boot, api, openapi, swagger]
triggers:
files: ['**/*Controller.java']
keywords: [openapi, swagger, versioning, problemdetails]
---
# Spring Boot API Design Standards
## **Priority: P0**
## Implementation Guidelines
### OpenAPI (Swagger)
- **SpringDoc**: Use `springdoc-openapi-starter-webmvc-ui`.
- **Annotations**: Use `@Operation` and `@ApiResponse`. Keep clean.
- **Schema**: Define examples in `@Schema` on DTOs.
### API Versioning
- **Strategy**: Prefer **URI Versioning** (`/api/v1/`) for caching simplicity.
- **Deprecation**: Use `@Deprecated` + OpenAPI flag.
### Error Handling (RFC 7807)
- **ProblemDetails**: Enable `spring.mvc.problem-details.enabled=true`.
- **Extension**: Extend `ProblemDetail` with custom fields if needed.
- **Security**: NEVER expose stack traces in API errors.
## Anti-Patterns
- **Untyped Response**: `**No Map<K,V>**: Return typed DTOs.`
- **Header Versioning**: `**No Headers**: Hard to test/cache.`
- **Undocumented**: `**No hidden APIs**: Use Swagger.`
## References
- [Implementation Examples](references/implementation.md)
This skill codifies Spring Boot API design standards focused on OpenAPI, versioning, and global error handling. It provides concrete rules and examples to produce discoverable, versioned, and secure REST APIs that integrate cleanly with SpringDoc and RFC 7807 ProblemDetails. The goal is consistent API behavior, better client caching, and safer error responses.
The skill prescribes using springdoc-openapi starter for automatic Swagger UI and annotation-driven documentation with @Operation, @ApiResponse, and @Schema examples on DTOs. It favors URI-based API versioning (e.g., /api/v1/) for caching and clarity, and mandates deprecation signals via @Deprecated plus OpenAPI flags. For errors it enables spring.mvc.problem-details and extends ProblemDetail for custom fields while preventing leakage of stack traces.
Why prefer URI versioning over header versioning?
URI versioning is simpler for caching, routing, and testing. Header versioning hides the version from caches and can complicate client and proxy behavior.
How do I add custom fields to ProblemDetails safely?
Extend ProblemDetail with explicit fields, serialize only non-sensitive data, and avoid including stack traces or internal identifiers visible to clients.
Are DTO examples required in @Schema?
Yes. Examples improve API discoverability and make generated docs and client code clearer for integrators.