openapi-to-application-java-spring-boot
Spring Boot application from an OpenAPI spec
Spec-first: the OpenAPI file is the source of truth. Generate interfaces and DTOs only at build time (never commit generated code), then hand-write the implementation. Verified with Spring Boot 4.0.8 and 4.1.1, openapi-generator 7.26.0 (Maven plugin, Gradle Groovy and Kotlin DSL), JDK 21+.
Step 0: Detect and gather
- Existing
pom.xml/build.gradle(.kts): keep its build tool and Spring Boot version, never upgrade implicitly, add the generator to it. Otherwise create the project with thecreate-spring-boot-java-projectskill (dependencies:web,validation,actuator; adddata-jpa,postgresql,securityonly if needed). - Get the spec (file, URL or pasted) and save it as
src/main/resources/openapi/<name>.yaml. Accept 3.0.x and 3.1.x; Swagger 2.0 must be converted first. - Ask only what the spec does not answer: persistence (in-memory vs database), authentication, package name.
Step 1: Review the spec
Check unique operationIds (they become method names), tags (they become one interface each), reusable components/schemas, required lists, validation constraints (minLength, maximum, pattern), error responses and securitySchemes. Flag gaps and fix the spec rather than the generated code.
Step 2: Configure the generator
Pin the version in a property; check the latest on Maven Central or the generator docs before changing it.
Maven (pom.xml, in <build><plugins>, before spring-boot-maven-plugin):