OpenAPI to Java DTO Generator
Paste an OpenAPI 3 spec — JSON or YAML — and get Java records or classes with Jackson annotations, enums and java.time mapping.
In-browser & private
OpenAPI spec (JSON or YAML)
Ctrl + Enter to generate
Java
Paste a spec on the left, or press Sample.
Types —
Fields —
Size 0 B
How the types are chosen
An OpenAPI schema carries more type information than raw JSON does, so this maps rather than guesses — but a few of those mappings are judgement calls, and they are worth stating.
numberbecomesBigDecimalunless the spec saysfloatordouble. Prices and quantities turn up in almost every real spec, and binary floating point is the wrong default for either.- Dates follow the format.
datebecomesLocalDate,date-timebecomesOffsetDateTime— notLocalDateTime, because an API timestamp carries an offset and dropping it loses information. allOfis flattened. It is how OpenAPI expresses composition, and Java has no structural intersection type — so the members are merged into one flat DTO.- Enums keep their wire value. A value like
in progresscannot be a Java constant, so the constant isIN_PROGRESSand the original string is retained for Jackson to serialise. - Names are converted, not renamed.
total_amountbecomestotalAmountand carries@JsonProperty("total_amount")so it still binds. Java keywords get a suffix — a field calledclasswould not compile.
Frequently asked questions
- Is my spec uploaded anywhere?
- No. The spec is parsed and the Java generated in your browser, so an internal API description never leaves the page.
- Which OpenAPI versions work?
- OpenAPI 3.0 and 3.1, in YAML or JSON, and the two give identical output. A 3.1 union such
as
type: [string, "null"]becomes the non-null type. Swagger 2.0 is refused with a pointer to a converter rather than half-supported, because its schemas live somewhere else entirely. - What happens to
$ref,allOfandoneOf? - A local
$refresolves to the generated class.allOfis flattened into one type, which is what a DTO has to be.oneOfandanyOfhave no Java equivalent and becomeObject, and a reference this document does not define does too. Every one of those is listed as a note under the toolbar rather than left for you to notice. - Why are numbers
BigDecimaland datesOffsetDateTime? - A bare
type: numbercarries money and quantities in most real specs, and binary floating point is the wrong default for either. Addformat: floatordoubleto get those.date-timeis an instant with an offset, which is whatOffsetDateTimemodels;datebecomesLocalDate. - Will the generated code compile as it stands?
- Yes. Names that collide once converted to Java are given distinct identifiers while
keeping their original wire names in
@JsonProperty, so nothing is quietly dropped and the files compile. You need Jackson on the classpath for the annotations, and Bean Validation if you tick that box. - Can I generate the Spring controllers too?
- Yes, from the same spec: the OpenAPI to Spring
controller generator writes one
@RestControllerper tag and imports these DTOs.