fix(naming): preserve word-initial acronyms in pascal-upper-acronyms style#3036
Open
schani wants to merge 8 commits into
Open
fix(naming): preserve word-initial acronyms in pascal-upper-acronyms style#3036schani wants to merge 8 commits into
schani wants to merge 8 commits into
Conversation
…style (#1363) Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Co-Authored-By: Claude <noreply@anthropic.com>
The upper-acronym-names.schema fixture was a top-level array, which
several language drivers can't handle: kotlinx renders top-level arrays
as `typealias TopLevel = JsonArray<T>` (doesn't compile), and the
typescript-zod driver can't locate the top-level schema when the array's
titled item type is named `SCUBAWaypointSchema` instead of
`TopLevelElementSchema` ("No schema found"). The CI failure surfaced on
kotlinx first; fail-fast hid the rest.
The top-level array is incidental to the acronym-naming bug being tested
(word-initial acronyms in type names). Wrapping the waypoints in a
top-level object exercises the identical naming path — C++ still emits
`SCUBAWaypoint`/`SCUBAManeuver`/`IDCardHTTP` with the fix and downcases
them without it — while working across all language drivers.
Co-Authored-By: Claude <noreply@anthropic.com>
…1363) cjson's generated deserializer does not validate enum values (a known, already-documented limitation shared with enum.schema, enum-large.schema, etc.), so the new upper-acronym-names.schema's .1.fail.enum.json sample round-trips instead of being rejected. Add it to the shared skipsEnumValueValidation list, matching the identical precedent in commit 349bc78 for all-of-additional-properties-false.schema. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Member
Author
|
Reopening to retrigger CI for the latest commit (no new run was generated for c0b8c24). |
# Conflicts: # test/fixtures.ts # test/languages.ts
…e-76a-78 # Conflicts: # test/languages.ts
The schema-cplusplus-upper-acronyms fixture was never listed in the CI matrix, so it never ran, and acronym_names.cpp included the multi-source header TopLevel.hpp while the fixture generates single-source output (quicktype.hpp), causing a compile failure when the fixture is actually executed. Include the generated single-source header and add the fixture to the cplusplus CI matrix entry so the acronym-preservation check runs. Co-Authored-By: Claude <noreply@anthropic.com>
Generated-output differences40 files differ — 0 modified, 40 new, 0 deleted |
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.
Bug
With
--type-style pascal-case-upper-acronyms, a word-initial acronym in atype name was incorrectly downcased to just its first letter capitalized,
while the same acronym elsewhere in the name (medial position) was correctly
kept fully upper-case.
Example from the issue: a JSON Schema with titles
SCUBAWaypointandSCUBAManeuver, generated with C++ +pascal-case-upper-acronyms, producedScubaWaypoint/ScubaManeuverinstead of the expectedSCUBAWaypoint/SCUBAManeuver. Further testing confirmed a mixed case:IDCardHTTPwasrendered as
IdCardHTTP— the medial acronymHTTPstayed upper-case, butthe word-initial acronym
IDwas incorrectly downcased.Root cause
In
packages/quicktype-core/src/support/Strings.ts,makeNameStylebuildsper-style
WordStylefunctions for the first word vs. the rest, and foracronym words vs. non-acronym words. The
"pascal"and"pascal-upper-acronyms"naming styles shared the samecaseblock and bothset
firstWordAcronymStyle = firstUpperWordStyle(capitalizes only the firstletter). That's correct for plain
"pascal"(acronyms aren't speciallypreserved there), but wrong for
"pascal-upper-acronyms", where aword-initial acronym should use
allUpperWordStyle— the same style alreadyused for non-initial acronym words in that mode (
restAcronymStyle = allUpperWordStyle).Fix
Split the
"pascal-upper-acronyms"case out of the shared"pascal"caseand set
firstWordAcronymStyle = allUpperWordStylefor it, whilefirstWordStyle(used for a non-acronym first word) keepsfirstUpperWordStyle."camel-upper-acronyms"is untouched — camelCaseidentifiers conventionally start lowercase regardless of whether the first
word is an acronym, so its existing
firstWordAcronymStyle = allLowerWordStylewas already correct and is out of scope for this issue.Test coverage
test/inputs/schema/upper-acronym-names.schema(+.1.jsonsample),a JSON Schema with a word-initial-acronym type (
SCUBAWaypoint,SCUBAManeuver) and a mixed word-initial+medial-acronym type(
IDCardHTTP), modeled directly on the issue's repro.schema-cplusplus-upper-acronymsintest/fixtures.ts/
test/languages.tsthat generates C++ from that schema with--type-style pascal-case-upper-acronyms --member-style camel-case-upper-acronyms.test/fixtures/cplusplus/acronym_names.cpp, a small driver file thatreferences the generated types by their exact expected names
(
quicktype::SCUBAWaypoint,quicktype::SCUBAManeuver,quicktype::IDCardHTTP) — so the fixture fails to compile if the namingregresses, not just at runtime.
Verification
(
g++reports'SCUBAWaypoint' is not a member of 'quicktype'; did you mean 'ScubaWaypoint'?, etc.), proving the test actually exercises the bug.QUICKTEST=true FIXTURE=schema-cplusplus-upper-acronyms script/test→ 1/1.--src-lang schema --lang c++ --type-style pascal-case-upper-acronyms --member-style camel-case-upper-acronyms) and confirmed it now emitsSCUBAManeuver/SCUBAWaypoint.pascal-casestill downcases(
IDCardHTTP->IdCardHttp), andcamel-case-upper-acronymsmember/property names are unaffected by this change.
npm run buildpasses.Fixes #1363
🤖 Generated with Claude Code