Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Could not use allOf #136

Closed medved72 closed 2 years ago

medved72 commented 3 years ago

I have default example from https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/ :

{
  "openapi": "3.0.1",
  "info": {
    "title": "OOG Reports API",
    "version": "v1"
  },
  "paths": {
    "/pets": {
      "patch": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Cat"
                  },
                  {
                    "$ref": "#/components/schemas/Dog"
                  }
                ],
                "discriminator": {
                  "propertyName": "pet_type"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "properties": {
          "pet_type": {
            "type": "string"
          }
        },
        "discriminator": {
          "propertyName": "pet_type"
        }
      },
      "Dog": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Pet"
          },
          {
            "type": "object",
            "properties": {
              "bark": {
                "type": "boolean"
              },
              "breed": {
                "type": "string",
                "enum": [
                  "Dingo",
                  "Husky",
                  "Retriever",
                  "Shepherd"
                ]
              }
            }
          }
        ]
      },
      "Cat": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Pet"
          },
          {
            "type": "object",
            "properties": {
              "hunts": {
                "type": "boolean"
              },
              "age": {
                "type": "integer"
              }
            }
          }
        ]
      }
    }
  }
}

When i try generate from this json scheme then i get empty interfaces:

export interface Pet {
  /**  */
  pet_type?: string;
}

export interface Dog {}

export interface Cat {}
Manweill commented 3 years ago

@arkraft @will7200 can you help him?

will7200 commented 3 years ago

codegen doesn't account for top level entities for allOf or oneOf. If you assign the allOf to a property of a model it works as intended.