openapi-first-codegen

Generate Spring Boot controllers and DTOs from an OpenAPI 3 contract using the Maven generator plugin.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Teams building Spring Boot HTTP APIs often drift between the OpenAPI spec and the actual controller code, producing mismatched contracts, unreviewable API changes, and generated code polluting coverage and static-analysis reports. This Skill makes the OpenAPI 3 spec the single source of truth by driving controllers and DTOs from api.yaml via openapi-generator-maven-plugin. ## Core Features & Use Cases - Contract-driven generation: Configures openapi-generator-maven-plugin for Spring Boot 3 / Jakarta with interfaceOnly=true, so generated FooApi interfaces define the contract while controllers stay hand-written. - Analysis hygiene: Provides exact exclusion rules for Jacoco, Spotless, SpotBugs, ArchUnit, NullAway, and Sonar so generated sources never inflate coverage deltas or trigger false positives. - Boundary enforcement: Enforces the controller implements <ApiName>Api pattern and the rule that generated DTOs never leak past the controller, using hand-written *DtoAdapter converters. - Use Case: A team adding a new REST endpoint edits api.yaml, runs the build, and implements the generated interface in a thin controller — the API change is reviewable as a YAML diff in the PR. ## Quick Start Apply the openapi-first-codegen skill to set up the Maven generator plugin and refactor my Spring Boot controller to implement the generated API interface from api.yaml.

Frequently Asked Questions about openapi-first-codegen

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

FAQPage Schema
How do I generate Spring Boot controllers from an OpenAPI spec with Maven?

Configure openapi-generator-maven-plugin with generatorName spring, library spring-boot, and interfaceOnly=true pointing at your api.yaml. The build generates FooApi interfaces under target/generated-sources, and you hand-write controllers that implement them.

How to exclude generated OpenAPI code from Jacoco coverage and Spotless?

Add **/api/** excludes to the Jacoco configuration and target/generated-sources/** to the Spotless java excludes block. Similar exclusions exist for SpotBugs, ArchUnit, NullAway, and Sonar so generated code never skews reports.

Should I use OpenAPI-first or springdoc annotations for Spring Boot APIs?

OpenAPI-first makes api.yaml the source of truth with reviewable YAML diffs, while springdoc documents annotation-driven code at runtime. The two approaches are mutually exclusive within the same module; pick spec-first when contract review matters.

Can generated OpenAPI DTOs be used in service or repository layers?

No, generated DTOs must not leak past the controller layer. Convert them at the boundary with a hand-written DtoAdapter so domain services only see domain types, keeping the generated contract decoupled from business logic.

Why do stale generated OpenAPI sources cause bugs?

Stale generated sources under target/ can mix DTO versions after a spec change, causing production bugs. Run mvn clean before commits that change api.yaml and add a CI step running mvn generate-sources with git diff --exit-code.