typeconv
typeconv copied to clipboard
'Required' not respected for JSON schema references
Hi, I am using typeconv to convert a JSON schema to suretype. I noticed that for required properties whose type is a referenced type, the 'required()' function call does not appear in the generated suretype declaration.
Repro: test.ts:
export interface A {}
export interface B {
a: A;
}
Run:
npx [email protected] -f ts -t jsc -o . test.ts
npx [email protected] -f jsc -t st -o ./out test.json
output:
import { suretype, v, compile } from 'suretype';
const schemaA = suretype({
name: "A",
title: "A"
}, v.object({}));
export interface A {
}
// ...
const schemaB = suretype({
name: "B",
title: "B"
}, v.object({
a: schemaA
}));
export interface B {
a: A;
}
should be
v.object({
a: schemaA.required()
})
The inlined type is created correctly, which also means that, for example, the ensureB function is of type never, so cannot be called.
I think that in this line, it should be wrap instead of wrapAnnotations:
https://github.com/grantila/core-types-suretype/blob/1ae1e9fa802054e7de7a5c89226aa074cc642b6d/lib/json-schema-to-suretype.ts#L666
Thanks for building this :)