Open CoalZombik opened 2 years ago
Hey, any updates on this one? Because I'm also looking for the unreachableDefinitions
feature, to generate reusable type.
Basically, I'm having a similar problem. Here's the example:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"Foo": {
"type": "object",
"properties": {
"baz": { "type": "string" }
}
},
"Bar": {
"type": "object",
"properties": {
"bum": { "type": "string" }
}
}
},
"oneOf": [
{ "$ref": "#/definitions/Bar" }
]
}
Received:
export interface Bar {
bum?: string;
[k: string]: unknown;
}
Expected:
export interface Bar {
bum?: string;
[k: string]: unknown;
}
export interface Foo {
baz?: string;
[k: string]: unknown;
}
I think this code fragment is incorrectly placed in the parseSchema function https://github.com/bcherny/json-schema-to-typescript/blob/master/src/parser.ts#L432
It would be better placed in the higher level "parse" function. Or maybe even in a new parseRoot function that would only be called on a top level schema and not recursively as parse is.
If root node is not plain object type,
unreachableDefinitions
doesn't work and unreached definitions is not exported.Calling:
json2ts -i test.schema.json -o test.d.ts --unreachableDefinitions
Package version: 10.1.5 Node version: 17.3.1
Number test
Received
Expected
Array test
Received
Expected
Logic subschemas test
Received
Expected
Object (only currently working)
Received and expected