json-schema-to-typescript
json-schema-to-typescript copied to clipboard
add ArrayObject into AST type
Happen to notice, JSTT fail to compile duplicate enum.
However,it works fine when the enum property is direct property of an object
example data
{
"type": "object",
"properties": {
"asDirectPropertyEnumType": {
"type": "integer",
"description": "duplicate enum",
"enum": [
1,
2,
3,
5,
1,
2,
6,
10,
1,
1,
2,
1,
2
]
},
"result": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"description": "total num"
},
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"enumType": {
"type": "integer",
"description": "duplicate enum",
"enum": [
1,
2,
3,
5,
1,
2,
6,
10,
1,
1,
2,
1,
2
]
},
"objectType": {
"type": "object",
"properties": {
"minAmount": {
"type": "integer",
"description": "minimum amount"
},
"maxAmount": {
"type": "integer",
"description": "maximum amount"
}
},
"description": "Object Propertie of ArrayObjectItem",
"additionalProperties": false
},
"env": {
"type": "integer",
"description": "env"
},
"version": {
"type": "string",
"description": "version"
}
},
"additionalProperties": false
},
"description": "data set"
}
},
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": false
}
In that way,I found out data like Object[] get no optimization in ./src/optimizer.
So i separate the type ARRAYOBJECT from just ARRAY,make sure the inside ast get optimized.
As result e2e test case compiled into
export interface ArrayObject {␊
result?: {␊
/**␊
* total num␊
*/␊
total?: number;␊
/**␊
* data set␊
*/␊
data?: {␊
/**␊
* duplicate enum␊
*/␊
enumType?: 1 | 2 | 3 | 5 | 6 | 10;␊
/**␊
* Object Propertie of ArrayObjectItem␊
*/␊
objectType?: {␊
/**␊
* minimum amount␊
*/␊
minAmount?: number;␊
/**␊
* maximum amount␊
*/␊
maxAmount?: number;␊
};␊
/**␊
* env␊
*/␊
env?: number;␊
/**␊
* version␊
*/␊
version?: string;␊
}[];␊
};␊
}␊