-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes bug in TypeScript gen
- Loading branch information
Showing
4 changed files
with
62 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { compileFromFile } from 'json-schema-to-typescript'; | ||
import { writeFileSync } from 'fs'; | ||
|
||
/** | ||
* Patches the types generated from 'json-schema-to-typescript' since the library has bugs. | ||
* @param {string} types | ||
* @return {string} | ||
*/ | ||
function patchTypes(types) { | ||
// Remove the 'Request1' object since the library does not generate the | ||
// correct type for the request 'oneOf' in the schema. | ||
// See: https://github.com/bcherny/json-schema-to-typescript/issues/381 | ||
types = types.replace(/ \& Request1/, ''); | ||
types = types.replace( | ||
`export type Request1 =\n | {\n [k: string]: unknown;\n }\n | {\n [k: string]: unknown;\n };\n`, | ||
'', | ||
); | ||
return types; | ||
} | ||
|
||
async function main() { | ||
let types = await compileFromFile('schema.json'); | ||
types = patchTypes(types); | ||
writeFileSync('types.ts', types); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters