Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf property is ignored when model marked as "type: object" in spec #221

Open
aldan95 opened this issue Feb 20, 2020 · 2 comments
Open

Comments

@aldan95
Copy link

aldan95 commented Feb 20, 2020

Two valid specifications (verified by swagger.io online validator):

openapi: 3.0.0
info:
  version: 1.0.0
  title: Swagger Petstore
tags:
  - name: pet
    description: Everything about your Pets
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: ""
      operationId: addPet
      responses:
        "405":
          description: Invalid input
components:
  schemas:
    Dog:
      allOf:
        - $ref: "#/components/schemas/Animal"
        - type: object
          properties:
            breed:
              type: string
    Animal:
      type: object
      discriminator:
        propertyName: className
      required:
        - className
      properties:
        className:
          type: string
        color:
          type: string
          default: red

generates public class Dog: Animal, but same spec with type: object added to Dog

openapi: 3.0.0
info:
  version: 1.0.0
  title: Swagger Petstore
tags:
  - name: pet
    description: Everything about your Pets
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: ""
      operationId: addPet
      responses:
        "405":
          description: Invalid input
components:
  schemas:
    Dog:
      type: object
      allOf:
        - $ref: "#/components/schemas/Animal"
        - type: object
          properties:
            breed:
              type: string
    Animal:
      type: object
      discriminator:
        propertyName: className
      required:
        - className
      properties:
        className:
          type: string
        color:
          type: string
          default: red

generates public class Dog: APIModel without properties at all

version 4.3.1

@rogerluan
Copy link

The specific request this issue is about was probably addressed as of v4.4.0 and v4.6.0 (after some fixes). However there's still something broken, as reported here #295, not sure if that would affect you.

@aldan95
Copy link
Author

aldan95 commented Jan 12, 2022

I've tested above samples with v.4.6.0.
Dog from first spec:

public class Dog: Animal {

    public var breed: String?

    public init(className: String, color: String? = nil, breed: String? = nil) {
        self.breed = breed
        super.init(className: className, color: color)
    }

    public required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: StringCodingKey.self)

        breed = try container.decodeIfPresent("breed")
        try super.init(from: decoder)
    }

    public override func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: StringCodingKey.self)

        try container.encodeIfPresent(breed, forKey: "breed")
        try super.encode(to: encoder)
    }

    override public func isEqual(to object: Any?) -> Bool {
      guard let object = object as? Dog else { return false }
      guard self.breed == object.breed else { return false }
      return super.isEqual(to: object)
    }
}

and Dog from second spec:

public class Dog: APIModel {

    public init() {
    }

    public required init(from decoder: Decoder) throws {
    }

    public func encode(to encoder: Encoder) throws {
    }

    public func isEqual(to object: Any?) -> Bool {
      guard object is Dog else { return false }
      return true
    }

    public static func == (lhs: Dog, rhs: Dog) -> Bool {
        return lhs.isEqual(to: rhs)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants