swagger-typescript
swagger-typescript copied to clipboard
Discriminator / mapping
Hi, I noticed that the contents of the 'discriminator' field seems to be unused.
Using this example swagger.json, generated using polymorphic classes with discriminator
"components": {
"schemas": {
"HotShearBaseDto": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"hotShearType": {
"enum": [
"CRANK",
"ROTARY",
"COMBI"
],
"type": "string"
}
},
"additionalProperties": false
},
"HotShearCOMBIDto": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/HotShearDto"
}
],
"properties": {
"crankRadius": {
"type": "number",
"format": "double",
"nullable": true
},
"bladesRadius": {
"type": "number",
"format": "double",
"nullable": true
}
},
"additionalProperties": false
},
"HotShearCRANKDto": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/HotShearDto"
}
],
"properties": {
"crankRadius": {
"type": "number",
"format": "double",
"nullable": true
}
},
"additionalProperties": false
},
"HotShearDto": {
"required": [
"hotShearType"
],
"type": "object",
"properties": {
"hotShearType": {
"type": "string"
},
"id": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "hotShearType",
"mapping": {
"CRANK": "#/components/schemas/HotShearCRANKDto",
"ROTARY": "#/components/schemas/HotShearROTARYDto",
"COMBI": "#/components/schemas/HotShearCOMBIDto"
}
}
},
"HotShearROTARYDto": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/HotShearDto"
}
],
"properties": {
"bladesRadius": {
"type": "number",
"format": "double",
"nullable": true
}
},
"additionalProperties": false
}
},
},
the following code is generated:
export interface HotShearBaseDto {
description?: string
hotShearType?: 'CRANK' | 'ROTARY' | 'COMBI'
/**
*
* - Format: uuid
*/
id?: string
}
export type HotShearCOMBIDto = {
/**
*
* - Format: double
*/
bladesRadius?: number
/**
*
* - Format: double
*/
crankRadius?: number
} & HotShearDto
export type HotShearCRANKDto = {
/**
*
* - Format: double
*/
crankRadius?: number
} & HotShearDto
export interface HotShearDto {
hotShearType: string
description?: string
/**
*
* - Format: uuid
*/
id?: string
name?: string
}
export type HotShearROTARYDto = {
/**
*
* - Format: double
*/
bladesRadius?: number
} & HotShearDto
The problem concerns HotShearDto as the swagger contains the following properties:
"discriminator": {
"propertyName": { "hotShearType",
"mapping": {
"CRANK": "#/components/schemas/HotShearCRANKDto",
"ROTARY": "#/components/schemas/HotShearROTARYDto",
"COMBI": "#/components/schemas/HotShearCOMBIDto"
}
}
which are ignored, as the generated code is as follows:
export interface HotShearDto {
hotShearType: string
What I would expect is very similar to HotShearBaseDto, without the question mark, e.g.
export interface HotShearBaseDto {
hotShearType: 'CRANK' | 'ROTARY' | 'COMBI'
It would be perfect if in addition, if possible, for each property in the mapping, its value was given, e.g.
export type HotShearCRANKDto = {
hotShearType: 'CRANK'
/**
*
* - Format: double
*/
crankRadius?: number
} & HotShearDto