yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
625 stars 146 forks source link

anyOf can be expressed in Swift for a specific case #315

Closed arasan01 closed 1 year ago

arasan01 commented 1 year ago

Concept

Patterns where a specific anyOf is used, such as the following, can be expressed by removing the constraint and embedding the Enum type expression in the model.

donkey:
  anyOf:
    - type: string
      enum:
        - asinus
        - hemippus
        - hemionus
        - kulan
        - onager
    - type: string
      enum:
        - polyodon
        - kiang
        - holdereri
    - type: string

to

        public enum KnownKind: String, Codable, Equatable, CaseIterable {
            case asinus = "asinus"
            case hemippus = "hemippus"
            case hemionus = "hemionus"
            case kulan = "kulan"
            case onager = "onager"
            case polyodon = "polyodon"
            case kiang = "kiang"
            case holdereri = "holdereri"
        }

        public var knownKind: String