Open codan84 opened 8 months ago
Yes, you can use Quicktype to generate TypeScript interfaces and enums for your JSON schemas. Quicktype supports resolving $ref
references to external files, so it should work well for your scenario.
Here's how you can do it:
Install Quicktype if you haven't already:
npm install -g quicktype
Use Quicktype to generate TypeScript interfaces and enums:
quicktype --src-lang schema --lang ts --combine-files schemas/draft.json schemas/new-draft.json schemas/enums/some-enum.json
This command tells Quicktype to generate TypeScript code (--lang ts
) by combining multiple schema files (--combine-files
). Replace the file paths with your actual file structure.
Quicktype will then generate a single TypeScript file containing interfaces and enums for each schema, including the referenced enums from enums/some-enum.json
. You can then use these TypeScript definitions in your code.
Thanks, this unfortunately will explode out of proportion with the number of schemas I am dealing with. Is there no way to automaticaly include all schemas in a directory (recursively)?
Furthermore - what version of quicktype are you using @SaintPepsi ? I am getting:
Error: Option parsing failed: UNKNOWN_OPTION: Unknown option: --combine-files.
@codan84 It seems that you don't need the --combine-files
option. Just specifying the files at the command line will combine them in the output.
I have a directory with multiple schemas, some of them $ref others:
Both
draft
andnew-draft
reference theenums/some-enum.json
.Is there a way I can convert this to 1 typescript file with interfaces/enums declared for each?