Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8894
Closed
Open
Issue created Mar 04, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-axios] `anyOf` creates same interface as `allOf`

Created by: ahilke

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using anyOf to describe an object, the created interface is incorrect. It contains properties from all subtypes, i.e. the result is what I would expect from allOf.

openapi-generator version

5.0.1 with openapi-generator-cli 2.1.26

OpenAPI declaration file content or url
  • Project to Reproduce
  • OpenAPI File
Simplified Schema:
Pet:
    anyOf:
      - $ref: '#/components/schemas/Cat'
      - $ref: '#/components/schemas/Dog'
Cat:
    type: object
    properties:
        petType:
            type: string
            enum: ["cat"]
        huntingSkill:
            type: string
    required:
        - petType
        - huntingSkill
Dog:
    properties:
        petType:
            type: string
            enum: ["dog"]
        packSize:
            type: integer
    required:
        - petType
Actual Output:
/**
 * 
 * @export
 * @interface Pet
 */
export interface Pet {
    /**
     * 
     * @type {string}
     * @memberof Pet
     */
    petType: PetPetTypeEnum;
    /**
     * 
     * @type {string}
     * @memberof Pet
     */
    huntingSkill: string;
    /**
     * 
     * @type {number}
     * @memberof Pet
     */
    packSize?: number;
}

/**
    * @export
    * @enum {string}
    */
export enum PetPetTypeEnum {
    Dog = 'dog'
}
Expected Output
/**
 * A representation of a cat.
 * @export
 * @interface Cat
 */
export interface Cat {
    /**
     * 
     * @type {string}
     * @memberof Cat
     */
    petType: CatPetTypeEnum;
    /**
     * 
     * @type {string}
     * @memberof Cat
     */
    huntingSkill: string;
}

/**
  * @export
  * @enum {string}
  */
export enum CatPetTypeEnum {
    Cat = 'cat'
}

/**
 * A representation of a dog.
 * @export
 * @interface Dog
 */
export interface Dog {
    /**
     * 
     * @type {string}
     * @memberof Dog
     */
    petType: DogPetTypeEnum;
    /**
     * 
     * @type {number}
     * @memberof Dog
     */
    packSize?: number;
}

/**
  * @export
  * @enum {string}
  */
export enum DogPetTypeEnum {
    Dog = 'dog'
}

/**
 * @type Pet
 * @export
 */
export type Pet = Cat | Dog;
Generation Details

Generator Name: typescript-axios

Steps to reproduce

README

Related issues/PRs
  • [BUG][Typescript] modeling anyOf vs oneOf: https://github.com/OpenAPITools/openapi-generator/issues/6376
Suggest a fix

Using oneOf, the expected interface is generated. It looks like anyOf is incorrectly using the same behaviour as allOf. Ideally, oneOf and anyOf should not produce the same code, as there is a semantic difference (see https://github.com/OpenAPITools/openapi-generator/issues/6376 linked above), but it would be much better already to model both anyOf and oneOf as a type union.

Assignee
Assign to
Time tracking