Bug Report Checklist
Description
AnyType is not defined in typescript generated code.
In some situations, schemas return any, this is handled in other languages where that is translated into something the language understands, examples:
Java: Object
C#: `Object
Rust: serde_json:Value
However, this translation is not made for typescript, and the generators write AnyType in such situations, leading to type errors:
Cannot find name 'AnyType'

openapi-generator version
5.0.0-SNAPSHOT
OpenAPI declaration file content or url
The part that is causing troubles look like this:
"cat": {
"allOf": [
{
"$ref": "#/components/schemas/Cat"
},
{
"description": "Cat information"
}
]
This was generated using @nestjs/swagger and the problem is that the generator is unable to understand the second part and that one ends in _AnyType_
This is a full example:
openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/person/display/{personId}:
get:
parameters:
- name: personId
in: path
required: true
description: The id of the person to retrieve
schema:
type: string
operationId: list
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Person"
components:
schemas:
Person:
type: object
discriminator:
propertyName: $_type
mapping:
a: '#/components/schemas/Adult'
c: Child
properties:
$_type:
type: string
lastName:
type: string
firstName:
type: string
Adult:
description: A representation of an adult
allOf:
- $ref: '#/components/schemas/Person'
- type: object
properties:
children:
type: array
items:
$ref: "#/components/schemas/Child"
firstChild:
allOf:
- $ref: '#/components/schemas/Person'
- description: First child
Child:
description: A representation of a child
allOf:
- type: object
properties:
age:
type: integer
format: int32
- $ref: '#/components/schemas/Person'
output using typescript-axios
/**
* A representation of an adult
* @export
* @interface Adult
*/
export interface Adult extends Person {
/**
*
* @type {Array<Child>}
* @memberof Adult
*/
children?: Array<Child>;
/**
*
* @type {Person & AnyType}
* @memberof Adult
*/
firstChild?: Person & AnyType;
}
/**
NOTE: AnyType is not defined anywhere.
Suggest a fix
The proposal is simple, adding a translation for AnyType -> object for all the typescript generators. This can be achieved adding one line to AbstractTypeScriptCodegen.java like the ones we have in other generators:
typeMapping.put("AnyType", "Object");
Bug Report Checklist
Description
AnyTypeis not defined in typescript generated code.In some situations, schemas return
any, this is handled in other languages where that is translated into something the language understands, examples:Java:ObjectC#: `ObjectRust:serde_json:ValueHowever, this translation is not made for
typescript, and the generators writeAnyTypein such situations, leading to type errors:Cannot find name 'AnyType'openapi-generator version
5.0.0-SNAPSHOT
OpenAPI declaration file content or url
The part that is causing troubles look like this:
This was generated using @nestjs/swagger and the problem is that the generator is unable to understand the second part and that one ends in
_AnyType_This is a full example:
output using
typescript-axiosNOTE:
AnyTypeis not defined anywhere.Suggest a fix
The proposal is simple, adding a translation for
AnyType->objectfor all thetypescriptgenerators. This can be achieved adding one line toAbstractTypeScriptCodegen.javalike the ones we have in other generators: