response-mapper

Implements API versioning and response projection mapping in Spring Boot using the Strategy, Handler, and Registry pattern.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill response-mapper-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: response-mapper
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/response-mapper
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill response-mapper-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Spring Boot REST APIs often need to serve multiple API versions or different response projections of the same entity without duplicating controllers or cluttering services with mapping logic. This Skill wires a version-aware response mapping layer so new versions are added by creating one strategy class, with no changes to existing handler or registry code. ## Core Features & Use Cases - Version Resolution: Resolves the target API version from the Accept header, URI segment, or query parameter via a MapperContextResolver. - Strategy-Based Mapping: Each version or projection is a @Component MapperStrategy that maps an entity to its version-specific DTO, registered automatically through a MapperRegistry. - Safe Fallbacks: Unknown or missing versions fall back to the latest schema instead of failing hard. - Use Case: A User API must keep serving a legacy v1 schema to old mobile clients while v3 adds a structured contact block. Add V3UserMapperStrategy, update ApiVersion.latest(), and existing clients keep working unchanged. ## Quick Start Apply the response-mapper skill to add version-aware DTO mapping to my Spring Boot UserController using the Accept header.

Frequently Asked Questions about response-mapper

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I support multiple API versions in a Spring Boot REST API?

Use a Strategy plus Registry pattern: define an ApiVersion enum, one MapperStrategy per version that maps the entity to its version-specific DTO, and a MapperHandler that resolves the version from the request and routes to the matching strategy. New versions require only one new @Component class.

How to resolve API version from the Accept header in Spring?

Parse the Accept header with a regex like application/vnd.api.(v\d+)\+json inside a resolver component, then map the captured group to your ApiVersion enum. Fall back to a query parameter or the latest version when the header is absent or unrecognized.

When should I use response-mapper instead of @JsonView?

Use response-mapper when whole schemas evolve across versions or backward compatibility must be maintained. Use @JsonView when versions differ by only one or two fields, and use separate controllers when version selection can happen at compile time.

What happens when a client requests an unknown API version?

The resolver maps blank or unrecognized version strings to ApiVersion.latest(), so unversioned or invalid requests receive the newest schema. The handler also falls back to the latest strategy if no strategy matches, throwing only if no latest strategy exists.

How do I add a new API version without changing existing code?

Add the new value to the ApiVersion enum and update latest() if needed, create the new DTO, then add a new @Component strategy implementing MapperStrategy with getSupportedVersion() and map(). The handler, registry, resolver, and existing strategies require zero changes.