Skip to content

fix(swift): scope JSON helpers to standalone output - #3094

Open
foobra wants to merge 2 commits into
glideapps:masterfrom
foobra:agent/swift-helper-visibility
Open

fix(swift): scope JSON helpers to standalone output#3094
foobra wants to merge 2 commits into
glideapps:masterfrom
foobra:agent/swift-helper-visibility

Conversation

@foobra

@foobra foobra commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Closes #3093

Swift standalone output can contain duplicate module-level newJSONDecoder and newJSONEncoder declarations when several generated files are compiled together. The original single-file fix used fileprivate, but the helpers were later moved to JSONSchemaSupport.swift for multi-file output and changed back to internal visibility.

This makes the visibility conditional:

  • standalone output: fileprivate
  • --multi-file-output: internal visibility in JSONSchemaSupport.swift

Added regression coverage for both rendering modes. Verified the unit tests, build, and Swift type-checking for generated standalone and multi-file output.

@github-actions

Copy link
Copy Markdown

Generated-output differences

314 files differ — 314 modified, 0 new, 0 deleted
1256 changed lines — +628 / −628

Open the generated-output report →

@github-actions

Copy link
Copy Markdown

Generated-output differences

314 files differ — 314 modified, 0 new, 0 deleted
1256 changed lines — +628 / −628

Open the generated-output report →

@foobra

foobra commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Relating this to #3105 (--nest-types), since both address multi-source standalone symbol collisions but at different scopes:

This PR (#3094) — scopes newJSONDecoder/newJSONEncoder to fileprivate in standalone output. Fixes the helper-symbol collision only. Child types stay at module scope, so repeated names like Image/Header/Payload across API models still collide. Keeps the flat type API (Image, not Root.Image).

#3105 (--nest-types) — opt-in option that nests child types under their top-level owner (Root.Image) and turns the helpers into static func members of the top-level type. Fixes both sibling-type and helper collisions, making each file fully self-contained. The trade-off is the type API changes (qualified Root.Image).

They're complementary rather than duplicates:

If only one is preferred, --nest-types (#3105) is the more complete fix for the collision class of issues (also covers #3104), but #3094 is the lower-impact change for users who can't adopt nesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift: use file-private JSON helpers for standalone output

1 participant