Skip to content

fix: deserialize OAS 3.1 scalar schema type into Set - #5266

Open
kalayciburak wants to merge 3 commits into
swagger-api:masterfrom
kalayciburak:fix/jsonschema-type-roundtrip
Open

fix: deserialize OAS 3.1 scalar schema type into Set#5266
kalayciburak wants to merge 3 commits into
swagger-api:masterfrom
kalayciburak:fix/jsonschema-type-roundtrip

Conversation

@kalayciburak

Copy link
Copy Markdown

Pull Request

Description

OpenAPI 3.1 serializes a single schema type as a JSON string ("type":"integer") via Schema31Mixin.TypeSerializer, while the model field is Set<String> types. Deserializing that scalar back into JsonSchema failed with:

Cannot construct instance of java.util.HashSet ... from String value ('integer')

This adds a matching TypeDeserializer that accepts both the scalar form and the multi-type array form ("type":["string","null"]), so JSON round-trips and convertValue keep the type set.

Fixes #5264

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)

Test plan

Executed:

./mvnw -pl modules/swagger-core -am test -Dtest=JsonSchemaTypeRoundTripTest,OpenAPI3_1DeserializationTest,SchemaDeserializationTest,JsonDeserializationTest -Dsurefire.failIfNoSpecifiedTests=false
# 41 tests, 0 failures

./mvnw -pl modules/swagger-core -am test -Dsurefire.failIfNoSpecifiedTests=false
# swagger-core: 752 tests, 0 failures

TypeSerializer writes a single type as a JSON string while the model
field is Set<String>. Add a matching TypeDeserializer so JsonSchema
JSON round-trips and convertValue keep a single type.

Fixes swagger-api#5264
@ewaostrowska ewaostrowska added the backlog label Aug 13, 2026 — with Claude
@@ -42,6 +48,7 @@ public abstract class Schema31Mixin {

@JsonProperty("type")
@JsonSerialize(using = TypeSerializer.class)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the serializer is used in an additional location and that it might be of relevance to attach the deserializer there as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, added TypeDeserializer on SortedSchemaMixin31 too

kalayciburak and others added 2 commits August 13, 2026 21:11
sortOutput replaces Schema31Mixin with SortedSchemaMixin31, so the
scalar OAS 3.1 type deserializer needs to live on that mixin too.
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]: JsonSchema fails with JSON round-trip

4 participants