Skip to content

[FEATURE] Swift generator #2334

@alexgavrisco

Description

@alexgavrisco

Why do we need this improvement?

Since Swift is the default language for iOS/macOS/etc, being able to generate API types from schemas is a significant dev experience improvement.
Adding support for Swift closes the parity loop for mobile stacks, reduces manual model writing, and prevents drift between platforms.

How will this change help?

  • Generates Swift DTOs that are immediately usable with JSONDecoder/JSONEncoder, minimizing boilerplate.
  • Improves cross-platform consistency and accelerates adoption of Modelina in mobile apps.
  • Encourages schema-first development by making Swift a first-class target alongside existing generators.

Screenshots

No response

How could it be implemented/designed?

  • Follow the existing “new generator” template (structure, presets, tests, examples).
  • Output struct models conforming to Codable, plus string/int enum types. Use CodingKey when property names differ from JSON keys.

Open question: handling untyped object (free-form/dynamic) and undecidable unions: Codable is strongly typed and doesn’t natively support “any” values. Options include:

  • Using a well-known type-erased value (e.g., AnyCodable) behind a generator option.
  • Emitting a custom JSONValue enum (string/number/bool/array/object/null).
  • Providing a strict mode that forbids dynamic values (fail fast) to enforce fully typed schemas.

I'd prefer to ship a strict mode that fails fast for types not supported OOTB by Codable, and add later a mode that uses a companion library with some container types (Apple's OpenAPI Generator works in a similar way).
Please let me know your thoughts.

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions