Skip to content

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

Open
@gereons

Description

@gereons

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions