indirect depended types generate unwanted type aliases
Closed this issue · 2 comments
EricWebsmith commented
Indirect dependency types will generate a type alias for each property, even for primitive types like strings and numbers. This will result in many unwanted type aliases in the final TypeScript code.
In the following JSON schema, we have three classes: Game, Ship, and Gun. Game and Ship are direct dependencies for the Master class, while Gun is an indirect dependency for _Master. In the generated TypeScript, Ship and Game appear as expected, but Gun produces two unnecessary type aliases.
JSON:
{
"$defs": {
"Game": {
"additionalProperties": false,
"properties": {
"ships": {
"items": {
"$ref": "#/$defs/Ship"
},
"type": "array"
}
},
"required": [
"ships"
],
"title": "Game",
"type": "object"
},
"Gun": {
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"damage": {
"title": "Damage",
"type": "number"
}
},
"required": [
"name",
"damage"
],
"title": "Gun",
"type": "object"
},
"Ship": {
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"speed": {
"type": "number"
},
"gun": {
"$ref": "#/$defs/Gun"
}
},
"required": [
"name",
"speed",
"gun"
],
"title": "Ship",
"type": "object"
}
},
"properties": {
"Game": {
"$ref": "#/$defs/Game"
},
"Ship": {
"$ref": "#/$defs/Ship"
}
},
"required": [
"Game",
"Ship"
],
"title": "_Master_",
"type": "object"
}
Typescript:
export type Name = string;
export type Damage = number;
export interface Game {
ships: Ship[];
}
export interface Ship {
name: string;
speed: number;
gun: Gun;
}
export interface Gun {
name: Name;
damage: Damage;
}
bcherny commented