Skip to content

Swift: use file-private JSON helpers for standalone output #3093

Description

@foobra

Problem

Swift output generated with --initializers contains module-level newJSONDecoder() and newJSONEncoder() helpers. When multiple schemas are generated separately and added to the same Swift target, each file defines the same functions and compilation fails with Invalid redeclaration.

The original fix in #1168 made these helpers fileprivate. They were later moved to JSONSchemaSupport.swift in commit ff61903, where they were changed back to internal visibility so model files could call the shared support file.

Expected behavior

  • Standalone/single-file output: helpers should be fileprivate, allowing multiple generated files in one module.
  • --multi-file-output: helpers in JSONSchemaSupport.swift must remain module-visible because model files call them.

Proposed fix

Emit fileprivate when multiFileOutput is disabled, and keep the current internal visibility when it is enabled. Add regression coverage for both modes.

Related: #1166, #1168.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions