You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating an OpenAPI 3.1 schema, an explicit @Schema(type = "...") on a property is resolved incorrectly. The scalar type is set correctly on the Schema object, but the types set is populated with ["string"]. Since the 3.1 serializer reads the types set, the property is emitted as type: "string" regardless of the declared type.
Goal: produce a correct OpenAPI 3.1 document for DTOs that use explicit @Schema(type = ...).
Annotation misbehaving:@Schema — an explicit type = "number" | "integer" | "boolean" is emitted as "string".
Correct case: properties relying on type inference (no explicit type in @Schema) serialize correctly. Only an explicitly declared scalar type is affected.
Framework: reproduces on plain swagger-core (ModelConverters + Json31); also observed via springdoc-openapi with springdoc.api-docs.version=openapi_3_1.
Downstream: the resulting spec misreports field types, which breaks OpenAPI-based type/client generation (numbers/booleans generated as string).
Under OpenAPI 3.0 (openapi31 = false) the same DTO serializes correctly, so this is specific to 3.1 generation.
Affected Version
2.2.47
Earliest version the bug appears in (if known):
Not fully bisected. Confirmed present in 2.2.47 and still present in 2.2.52 (latest release at time of filing).
Steps to Reproduce
Add a DTO with explicit @Schema(type = ...) properties and resolve it in OpenAPI 3.1 mode:
importio.swagger.v3.core.converter.AnnotatedType;
importio.swagger.v3.core.converter.ModelConverters;
importio.swagger.v3.core.converter.ResolvedSchema;
importio.swagger.v3.core.util.Json31;
importio.swagger.v3.oas.annotations.media.Schema;
importjava.math.BigDecimal;
publicclassRepro {
enumFreq { DAY, WEEK, MONTH }
staticclassDto {
@Schema(title = "Inferred") publicBigDecimalinferred; // no explicit type (control)@Schema(title = "Amount", type = "number") publicBigDecimalamount;
@Schema(title = "Count", type = "integer") publicIntegercount;
@Schema(title = "Flag", type = "boolean") publicBooleanflag;
@Schema(title = "Unit") publicFrequnit; // enum (control)
}
publicstaticvoidmain(String[] args) {
ModelConvertersconverters = newModelConverters(true); // openapi31 = trueResolvedSchemaresolved =
converters.resolveAsResolvedSchema(newAnnotatedType(Dto.class));
// root cause: scalar type is correct, but the "types" set is ["string"]resolved.schema.getProperties().forEach((name, s) ->
System.out.println(name + " -> getType()=" + s.getType() + " getTypes()=" + s.getTypes()));
System.out.println(Json31.pretty(resolved.schema));
}
}
Resolve with new ModelConverters(true) (OpenAPI 3.1 mode) and serialize with Json31.
Observe the serialized output and inspect the resolved Schema objects.
Description of the problem/issue
When generating an OpenAPI 3.1 schema, an explicit
@Schema(type = "...")on a property is resolved incorrectly. The scalartypeis set correctly on theSchemaobject, but thetypesset is populated with["string"]. Since the 3.1 serializer reads thetypesset, the property is emitted astype: "string"regardless of the declared type.@Schema(type = ...).@Schema— an explicittype = "number" | "integer" | "boolean"is emitted as"string".typein@Schema) serialize correctly. Only an explicitly declared scalartypeis affected.ModelConverters+Json31); also observed via springdoc-openapi withspringdoc.api-docs.version=openapi_3_1.example, so it is distinct from [Bug]: Number example treated as a string when generating swagger file. #5061 / fix: treat number example as number and not string #5062 (numeric example serialization).string).Under OpenAPI 3.0 (
openapi31 = false) the same DTO serializes correctly, so this is specific to 3.1 generation.Affected Version
2.2.47
Earliest version the bug appears in (if known):
Not fully bisected. Confirmed present in 2.2.47 and still present in 2.2.52 (latest release at time of filing).
Steps to Reproduce
Add a DTO with explicit
@Schema(type = ...)properties and resolve it in OpenAPI 3.1 mode:Resolve with
new ModelConverters(true)(OpenAPI 3.1 mode) and serialize withJson31.Observe the serialized output and inspect the resolved
Schemaobjects.Expected Behavior
The declared type is preserved:
{ "properties": { "inferred": { "type": "number" }, "amount": { "type": "number" }, "count": { "type": "integer" }, "flag": { "type": "boolean" }, "unit": { "type": "string", "enum": ["DAY", "WEEK", "MONTH"] } } }Actual Behavior
Every property with an explicit scalar type collapses to
"string":{ "properties": { "inferred": { "type": "number" }, // OK (inferred, control) "amount": { "type": "string" }, // WRONG, declared "number" "count": { "type": "string" }, // WRONG, declared "integer" "flag": { "type": "string" }, // WRONG, declared "boolean" "unit": { "type": "string", "enum": ["DAY", "WEEK", "MONTH"] } // OK (enum, control) } }inferred(inferred type) andunit(enum) serialize correctly — the defect is limited to an explicitly declared scalar type.Inspecting the resolved (pre-serialization)
Schemaobjects shows the root cause — the scalar type is right, thetypesset is wrong:Logs / Stack Traces
No exception or log output — the schema is generated silently with the wrong type.
Additional Context
new ModelConverters(false)) produces correct types, confirming this is a 3.1-generation regression.@Schematype/implementation ignored under OpenAPI 3.1).exampleserialization; this issue is about the propertytypeand reproduces with noexamplepresent.typesset to its scalartypeproduces a correct 3.1 document.Checklist
Repro.java