Enum Constant Description Provider
A victools CustomDefinitionProviderV2 that builds a oneOf schema node for enum classes annotated with @EnumAsOneOf, embedding each constant's JsonPropertyDescription as a description field.
For an enum like:
@EnumAsOneOf
enum class Priority {
@JsonPropertyDescription("Needs same-day response") URGENT,
@JsonPropertyDescription("Standard turnaround") NORMAL,
OTHER
}this provider produces:
{ "type": "string", "oneOf": [
{ "const": "URGENT", "description": "Needs same-day response" },
{ "const": "NORMAL", "description": "Standard turnaround" },
{ "const": "OTHER" }
]}The const value defaults to the Java name of the constant. If the enum defines a @JsonValue method or a @JsonProperty rename, that overridden value is used instead.
This provider is installed unconditionally on the schema generator. Victools calls it for every type it resolves, including enums nested inside collections and records at any depth. The @EnumAsOneOf check inside provideCustomSchemaDefinition is what decides whether oneOf is emitted — unannotated enums receive null and fall through to victools' default behaviour.
Returns null (letting victools handle the type normally) when:
the type is not an enum class,
the enum is not annotated with @EnumAsOneOf,
no constant carries a non-empty JsonPropertyDescription, or
any constant serialises to a non-string value (e.g. an
Intfrom a@JsonValuemethod) — in that case writing"type": "string"would be wrong.
This class is public so that callers outside this module can wire it directly:
schemaGeneratorConfigBuilder().with(EnumConstantDescriptionProvider(objectMapper))Java callers can do the same with new EnumConstantDescriptionProvider(objectMapper).