Repository navigation
OpenAPI
The openApi feature adds io.swagger.v3.oas.annotations.media.Schema metadata, so tools such as springdoc or
swagger-core describe the DTO in the generated API document using the schema's own wording.
modelmaker {
features {
openApi { enabled = true }
}
}| Schema keyword | Where | Emitted as |
|---|---|---|
description (top-level) |
class | @Schema(description = "...") |
description (property) |
getter or field | @Schema(description = "...") |
example (property) |
getter or field | @Schema(example = "...") |
property listed in required
|
getter or field | requiredMode = Schema.RequiredMode.REQUIRED |
{
"description": "A customer of the shop.",
"required": ["id"],
"properties": {
"id": { "type": "string", "description": "Customer identifier.", "example": "C42" },
"nickname": { "type": "string" }
}
}@Schema(description = "A customer of the shop.")
public final class Customer {
@Schema(description = "Customer identifier.", example = "C42", requiredMode = Schema.RequiredMode.REQUIRED)
public String getId() {
return id;
}
public @Nullable String getNickname() { // no @Schema - nothing to say about it
return nickname;
}
}Two rules follow from that:
- A class
@Schemais emitted only when the schema has adescription. - A property
@Schemais emitted only when the property has adescriptionor anexample.requiredModealone never triggers one - a required property with no prose gets no annotation.
example must be a JSON primitive, and it is rendered into the annotation as a string literal:
"loyaltyPoints": { "type": "integer", "example": 42 }@Schema(example = "42")That matches @Schema(example = ...), whose declared type is String. A non-primitive example (an object or an
array) is ignored.
Facets such as minimum, maximum, pattern, minLength and maxLength are not copied into @Schema. They
are emitted as jakarta.validation annotations by the validation feature, which springdoc and
swagger-core already read when building the document - duplicating them into @Schema would create two sources of
truth for the same constraint.
So a typical API project turns on all three features:
modelmaker {
features {
jackson { enabled = true }
validation { enabled = true }
openApi { enabled = true }
}
}jackson fixes the property names and order, validation supplies the facets, openApi supplies the prose.
@Schema sits on the getters by default and is the first annotation on a member, before Jackson's and the
validation constraints. See Feature Configuration.
dependencies {
implementation("io.swagger.core.v3:swagger-annotations-jakarta:2.2.30")
}The -jakarta artifact is the one that matches the jakarta.* namespace used elsewhere in the generated code. It is
required on the compile classpath whenever openApi is on.
ModelMaker - Apache License 2.0 - Issues - Wiki index
Start here
Schemas
Output
Features
Integration
Reference