OpenAPITools / OpenAPITools/openapi-generator

[Swift] Inheritance issue

Open
#2,588 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Swift Feature: Composition / Inheritance Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Hi guys, I've installed the latest generator via homebrew and now I'm trying to generate a client for my iOS app.
I appreciate structs over classes (Apple does too!), but here is one problem with inheritance, as Swift structs being value types do not support inheritance. There's a base class and a few descendants described in API yaml. Descendants do not inherit base's properties and I get invalid API client.

openapi-generator version

3.3.4 (latest available with Homebrew

OpenAPI declaration file content or url

here is a gist

Sorry, I can't provide the full spec

Command line used for generation

openapi-generator generate -l swift4 -i XXX

Suggest a fix/enhancement

I would think of either generating abstract descendants as classes or use a composition pattern and stay with structs. Though I am not sure either is easily possible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Swift4 generator entry point used by openapi-generator generate -l swift4 -i XXX and reproduce the output using the OpenAPI YAML linked in the gist. Compare the generated base type and descendants to confirm where inherited properties are lost. Done means the generated iOS client represents the declared inheritance correctly and produces valid Swift code.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.