Open lukas-runge opened 10 months ago
I just found a workaround when having a deeper look into the inner workings of typescript-json-schema
and at least found a viable workaround for my use case.
By passing the files
array into the buildGenerator
as onlyIncludeFiles
-parameter I can match the cli's behaviour. π₯³
I published the workaround under a new branch in my demo repo for reference: https://github.com/lukas-runge/tjs-bug-demo/commit/5f3de743f08f3ca838659fa701353fcb1d344c66
import * as TJS from "typescript-json-schema";
const settings: TJS.PartialArgs = { required: true };
const files = ["src/udr.next.d.ts"];
const program = TJS.getProgramFromFiles(files);
const schema = TJS.buildGenerator(program, settings, files)?.getSchemaForSymbol("Device")
console.log(JSON.stringify(schema, null, 4));
I still find this shouldn't be the default behaviour. Maybe someone more experienced can explain what's actually going on here under the hood and if it's a bug or a feature. In any case I'd say there needs to be documentation on a programmatical
implementation that matches the one of the cli
. π
Best regards, @lukas-runge
When trying to use
typescript-json-schema
programatically
I stubled across some weird behaviour that did not match thecli
output. I build a minimal example to reproduce this issue fast: https://github.com/lukas-runge/tjs-bug-demo. πThe cli command:
The programatic implementation of the "same" thing:
The programatically generated schema is missing one required property (
test
):I tried to fix or workaround this on my own but didn't get it resolved. I would really appreciate if someone has an idea for a quick workaround or even fix. π
Looking forward to getting this resolved! π
Best regards, @lukas-runge