OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

[BUG][SWIFT4] Inherited enumerations are not being generated correctly #2370

Open lopesmcc opened 5 years ago

lopesmcc commented 5 years ago
Description

Whenever a definition is inheriting enumeration fields (using allOf), these end up being generated without any options.

public enum Status: String, Codable {
}

Those same enumerations are being generated correctly on the original definition.

Our spec is still using swagger 2.0.

openapi-generator version

Happening on v3.3.4. Was using swagger-codegen before and did not have this issue.

OpenAPI declaration file content or url
ParentObject:
    type: object
    required:
      - id
      - status
    properties:
      id:
        type: string
      status:
        type: string
        enum:
          - generate
          - activate
          - suspend
          - refund
          - expire
          - burn
  NamedChildObject:
    allOf:
      - $ref: '#/definitions/ParentObject'
      - type: object
        properties:
          name:
          type: string

Using the example above, NamedObject will look like:

public struct NamedChildObject: Codable {

    public enum Status: String, Codable {
    }
    public var _id: String
    public var status: Status

    public init(_id: String, status: Status) {
        self._id = _id
        self.status = status
    }

    public enum CodingKeys: String, CodingKey { 
        case _id = "id"
        case status
    }
}
lopesmcc commented 5 years ago

Seems to me that at DefaultCodegen.java:312, we should be iterating through the model allVars, and not only vars. This way, it would generate the enumVars metadata even for inherited data.

Not sure what kind of impact this would have for other generators.