Honor PropertyNamingStrategy for get/is-prefixed property names#5192
Open
seonwooj0810 wants to merge 1 commit into
Open
Honor PropertyNamingStrategy for get/is-prefixed property names#5192seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
The "avoid clobbering get/is names" hack in ModelResolver replaced the Jackson-resolved property name with the raw member name for any member whose name starts with a get/is prefix followed by a lower-case letter. When a custom PropertyNamingStrategy (e.g. SNAKE_CASE) was configured, this clobbered the translated name: record components such as issuanceDate were emitted as "issuanceDate" instead of "issuance_date", while sibling fields like familyName were correctly translated. Only apply the hack when no PropertyNamingStrategy is configured, so the strategy is honored uniformly. The original swagger-api#415 (Scala is_persistent) and swagger-api#2635 (JAXB-renamed is-prefixed fields) behavior is preserved, as neither configures a naming strategy. Reported in springdoc/springdoc-openapi#3293. Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.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.
Description
When a custom
PropertyNamingStrategy(e.g.SNAKE_CASE) is configured on the mapper,ModelResolverproduced inconsistent schema property names: most fields were translated, but any property whose member name starts with aget/isprefix followed by a lower-case letter kept its original camelCase name.Example (
SNAKE_CASE, Java record):Produced:
instead of the expected
issuance_date,issuing_country,issuing_authority.Root cause
The "avoid clobbering properties with get/is names" hack (added for #415) overwrites the Jackson-resolved property name with the raw member name whenever the member name starts with
get/is+ lower-case. For record components the accessor's physical name is the bare component name (issuanceDate), which starts withis, so the hack replaced the strategy-translatedissuance_datewithissuanceDate.Fix
Only apply the hack when no
PropertyNamingStrategyis configured. When a strategy is active the resolved name is authoritative and must be honored uniformly. The hack was only ever needed to restore raw names in the absence of a strategy:is_persistentwrongly shortened to_persistent) — default mapper, no strategy → hack still runs.is-prefixed fields keeping their original name) — JAXB mapper, no strategy → hack still runs.Both existing test cases continue to pass.
This bug surfaces through springdoc and was traced to swagger-core: springdoc/springdoc-openapi#3293.
Type of Change
Checklist
Test evidence
Added
RecordPropertyNamingStrategyTest(inswagger-java17-support, which compiles at Java 17 for records). It fails onmaster(issuanceDatenot translated) and passes with this change.Verification done: reproduced on
master; ran the full test suites forswagger-core,swagger-jaxrs2(incl.ReaderTest#testModelResolverXMLPropertiesNamefor #2635) andswagger-java17-support— all green (BUILD SUCCESS).