json-schema-to-typescript
json-schema-to-typescript copied to clipboard
allOf is generated as an union type
We are facing a very strange behavior with allOf: the generated type is a type alias instead of a proper type.
Take this code sample:
import {compile, JSONSchema} from "json-schema-to-typescript";
const schema: JSONSchema = {
allOf: [
{
type: "object",
properties: {
foo: {
type: "string"
}
}
},
{
type: "object",
properties: {
bar: {
type: "string"
}
}
}
]
};
compile(schema, 'Schema').then((output) => {
console.log(output);
})
The content of output is:
export type Schema = {
foo?: string;
[k: string]: unknown;
} & {
bar?: string;
[k: string]: unknown;
}
Instead of the expected:
export type Schema = {
foo?: string;
bar?: string;
[k: string]: unknown;
}
It creates a very big quality issue: every schema referenced by a allOf directive is exported as a discrete type, making them publicly available and thus contractual. They are internal schemas, just known at schema-writing time and they should not be emitted as some public types.
Is this a known issue?