fix: let explicit @Schema(format) override type-derived format (#5185)#5186
Open
seonwooj0810 wants to merge 1 commit into
Open
fix: let explicit @Schema(format) override type-derived format (#5185)#5186seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
…er-api#5185) `@Schema(format = "uri-reference")` on a `java.net.URI` field was ignored because `resolveSchemaMembers` only applied the annotation format when the schema had no format yet. For `java.net.URI` the `PrimitiveType` already sets `format: uri`, so the user-specified `uri-reference` was dropped. An explicit `format` on `@Schema` expresses the user's intent and must take precedence over a format derived from the property type. A URI field without an explicit format still resolves to the default `uri`. Co-Authored-By: Claude Opus 4.8 (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.
Fixes #5185
Problem
When a field carries an explicit
@Schema(format = "...")whose owning type already resolves to a built-in format, the explicit format is silently dropped. The reported case isjava.net.URIannotated with@Schema(format = "uri-reference"): the type resolves toformat: urifirst, and because the schema already has a (type-derived) format, the explicit override is ignored — producingformat: uriinstead of the requesteduri-reference.@Schema#formatis documented as "Provides an optional override for the format", so an explicitly supplied format should win over the one inferred from the property type.Change
In
ModelResolver.resolveSchemaMembers(...)the format was only applied when the schema did not already have one:This is relaxed so that a non-blank explicit format always takes precedence over a type-derived format:
This fixes the
uri-referencecase in #5185 and any other type whose explicit@Schema(format)differs from its inferred format, without needing a per-type enum entry. A field with no explicit@Schema(format)still falls back to the type-derived format (e.g. plainURI→uri).Tests
Added
Ticket5185Testcovering both OpenAPI 3.0 and 3.1 resolution:@Schema(format = "uri-reference") URIresolves toformat: uri-referenceURI(no annotation) still resolves toformat: uriTest evidence
Full
swagger-coremodule suite after the change:Verification done: (1) No in-flight PR —
gh pr list --search "5185" / "uri-reference"returned none; no open PR touches this path. (2) No active claim — issue is unassigned and has no claim comments. (3) Code-focused — change is inModelResolver.javaplus a Java test. (4) Bug still present onmaster— the guarded condition is unchanged atModelResolverline 3184. (5) No parent epic closing this. Branch is based directly on currentmaster(no rebase needed).Note: the issue suggested adding a dedicated
URI_REFERENCEPrimitiveTypeenum entry. This PR instead fixes the root cause — explicit@Schema(format)should always override the inferred format — which coversuri-referenceand any future explicit-override case with a smaller, more general change. Happy to switch to the enum-based approach if maintainers prefer it.