Skip to content

fix: apply explicit @Schema(type) to the types set under OpenAPI 3.1#5234

Open
forhadmethun wants to merge 1 commit into
swagger-api:masterfrom
forhadmethun:fix/oas31-explicit-type-5233
Open

fix: apply explicit @Schema(type) to the types set under OpenAPI 3.1#5234
forhadmethun wants to merge 1 commit into
swagger-api:masterfrom
forhadmethun:fix/oas31-explicit-type-5233

Conversation

@forhadmethun

Copy link
Copy Markdown

Description

Under OpenAPI 3.1, an explicit @Schema(type = ...) was applied via the legacy scalar setType(), while the 3.1 serializer reads the types set. The set kept its default ("string"), so number / integer / boolean fields were rendered as string. This change populates the types set when openapi31 is enabled, mirroring the handling of the plural types() attribute directly below.

AnnotationsUtils.getSchemaFromAnnotation:

if (StringUtils.isNotBlank(schema.type())) {
    if (openapi31) {
        schemaObject.setTypes(new LinkedHashSet<>(Arrays.asList(schema.type())));
    } else {
        schemaObject.setType(schema.type());
    }
}

Before / After (OpenAPI 3.1) — given @Schema(type = "number") BigDecimal amount;:

  • Before: amount: { type: "string" }
  • After: amount: { type: "number" }

This is a bug fix. It is distinct from #5061 / #5062 (numeric example serialization); it concerns the property type and reproduces with no example present. Fields relying on type inference (no explicit type) were already correct.

Fixes: #5233

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

Added io.swagger.v3.core.resolving.v31.Ticket5233Test, asserting that explicit number / integer / boolean types land in the types set under OpenAPI 3.1, with inferred-type and enum properties as controls. The full swagger-core module test suite passes locally (721 tests, 0 failures).

Under OpenAPI 3.1 an explicit @Schema(type = ...) was applied via the legacy
scalar setType(), while the 3.1 serializer reads the types set. The set kept its
default ("string"), so number/integer/boolean fields were rendered as string.
Populate the types set when openapi31 is enabled, mirroring the handling of the
plural types() attribute directly below.

Fixes swagger-api#5233
@ewaostrowska ewaostrowska added the backlog label Jul 16, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Explicit @Schema(type = "number"|"integer"|"boolean") is emitted as "string" under OpenAPI 3.1

2 participants