OpenAPITools / OpenAPITools/openapi-generator

[BUG] Model inheritance in Java and Swift is broken in v6.0.0

Open
#12,650 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Installed v6.0.0, noticed that base class / derived class relationships no longer show up in generated Java and Swift models.

OpenAPI declaration file content or url
components:
  schemas:
    BaseClass:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
    DerivedClass:
      type: object
      allOf:
        - $ref: "#/components/schemas/BaseClass"
        - type: object
          properties:
            derivedData:
              type: string
Steps to reproduce

Generate models using openapi-generator generate -i spec.yml -g java and openapi-generator generate -i spec.yml -g swift5 --additional-properties=useClasses=true

The resulting Java code for DerivedClass looks like this:

public class DerivedClass {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  private Integer id;
  // ...
}

and the Swift version has

public final class DerivedClass: Codable, JSONEncodable, Hashable {
  // ...
}

i.e. in both cases, information about the inheritance is lost.

In the Swift case, the base class is erroneously generated as final,

public final class BaseClass: Codable, JSONEncodable, Hashable {
  // ...
}

which prohibits inheriance, even if the code for DerivedClass were generated correctly.

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 supplied OpenAPI schema and reproduce the issue using the Java and Swift generator commands. Compare the generated DerivedClass and BaseClass outputs to determine where inheritance is lost. Done means DerivedClass preserves its relationship to BaseClass in both languages and Swift BaseClass is no longer final.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, 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.