OpenAPIDTO 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
Advertisement
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.

  • number becomes BigDecimal unless the spec says float or double. Prices and quantities turn up in almost every real spec, and binary floating point is the wrong default for either.
  • Dates follow the format. date becomes LocalDate, date-time becomes OffsetDateTime — not LocalDateTime, because an API timestamp carries an offset and dropping it loses information.
  • allOf is 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 progress cannot be a Java constant, so the constant is IN_PROGRESS and the original string is retained for Jackson to serialise.
  • Names are converted, not renamed. total_amount becomes totalAmount and carries @JsonProperty("total_amount") so it still binds. Java keywords get a suffix — a field called class would not compile.

More free tools