fix: keep a type on the rate limit headers under OpenAPI 3.1 - #2124
Merged
Conversation
Upgrading springdoc to 3.1.0 (#2112) also changed the spec version it emits: springdoc 3.x defaults springdoc.api-docs.version to OPENAPI_3_1, where 2.8.13 defaulted to OPENAPI_3_0. That was a side effect of the bump rather than a decision, and it silently dropped a field from the document. new Schema<>().type("integer") sets only the legacy string `type` and leaves the 3.1 `types` set null, and a 3.1 document does not serialize the former. The four rate limit headers have therefore been documented with no type at all since the upgrade. Building them through IntegerSchema populates both fields, so they keep a type whichever version springdoc emits. The dev configuration pins api-docs back to 3.0. Beyond restoring the document as it was, it silences a warning that OpenAPI 3.1 draws out of swagger-core 2.2.52 on every schema springdoc clones: SpringDocUtils : Json Processing Exception occurred: Cannot construct instance of `java.util.HashSet` [...] from String value ('integer') (through reference chain: io.swagger.v3.oas.models.media.JsonSchema["type"]) Its 3.1 mapper writes a single type as a bare string but only reads an array back, so cloneViaJson cannot re-read what it just wrote. It logs and falls back to the original object, so the document still renders. A schema with two types serializes as an array and round-trips fine, which is why only some schemas trip it. Nothing in this repository can fix that asymmetry; only avoiding 3.1 avoids it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Accessing api-docs logs:
Chasing it turned up a second, silent problem in our own document. Both come from the same change.
What changed
46335e7 (#2112) bumped springdoc 2.8.13 to 3.1.0. springdoc 3.x defaults
springdoc.api-docs.versiontoOPENAPI_3_1; 2.8.13 defaulted toOPENAPI_3_0. The emitted spec version flipped as a side effect of the bump.The silent bug, fixed here
new Schema<>().type("integer")sets only the legacy stringtypeand leaves the 3.1typesset null, and a 3.1 document does not serialize the former:So all four rate limit headers have been documented with no type since the upgrade.
IntegerSchemapopulates both fields and is correct under either spec version, so this is fixed independently of which version we emit.The logged warning
swagger-core 2.2.52's 3.1 mapper writes a single schema type as a bare string but only reads an array back:
SpringDocUtils.cloneViaJsoncannot re-read what it just wrote. It logs atwarnand returns the original object instead of a copy, so api-docs still render — the cost is a shared schema instance where a clone was intended. A two-typed schema round-trips fine, which is why only some schemas trip it.Nothing in this repository can fix that asymmetry, so the dev configuration pins
api-docsback toopenapi_3_0. That restores the document as it was before #2112 and silences the warning, since the 3.0 mapper is symmetric on stringtype. Verified the key actually binds — a mistyped property would bind silently — resolving toOPENAPI_3_0/ spec3.0.1.The pin is dev-only, as requested. Deployments that want it will need it in their own configuration;
deploy/openshift/application.ymlanddeploy/docker/configuration/application.ymlare untouched.Tests
shouldGiveTheRateLimitHeadersATypeInEitherSpecVersionasserts the header schema serializes with"type":"integer"under both the 3.0 and 3.1 mappers, so it holds whichever version springdoc defaults to next. Fail-first checked: red withnew Schema<>().type(...)restored.Full server suite passes, 1132 tests.
🤖 Generated with Claude Code