[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
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
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.