Skip to content

Commit

Permalink
fix: catch ts-json-schema error and pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnig committed Feb 18, 2022
1 parent 85eabaf commit 5bdc310
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/cli/src/helper/generateSchema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $RefParser from '@apidevtools/json-schema-ref-parser';
import * as ts from 'ts-json-schema-generator';
import { log } from '../log.js';
interface GenerateSchemaOptions {
removeDateTime: boolean;
}
Expand Down Expand Up @@ -40,6 +41,19 @@ export class GenerateGlobalSchema {
return '';
}

if (e.diagnostics) {
e.diagnostics.forEach(
(element: { messageText: string; file: { fileName: string } }) => {
log({
component: 'cli',
warning: element.messageText,
details: element.file.fileName,
});
},
);
return '';
}

throw e;
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function writeControllerJson() {

export async function writeSchemaJson() {
const config = await getConfig();
const schema = await generateSchema(config.entry, { removeDateTime: false });
let schema = await generateSchema(config.entry, { removeDateTime: false });
if (!schema) {
schema = '{}';
}

writeFile(join(config.outdir, 'flux-schema.json'), schema);
}
Expand Down

0 comments on commit 5bdc310

Please sign in to comment.