Skip to content

Commit

Permalink
feat: add warning for no entry for json schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Jul 6, 2020
1 parent 5673188 commit c4e2c51
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"minimist": "1",
"protobufjs": "6",
"ts-lib-utils": "2",
"tslib": "2",
"tslib": "1 || 2",
"typescript": "3"
},
"bin": {
Expand Down
6 changes: 5 additions & 1 deletion src/json-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import {

export function generateJsonSchemas(context: Context) {
const definitions = getAllDefinitions(context)
return context.declarations.filter(m => (m.kind === 'object' || m.kind === 'array' || m.kind === 'union') && m.entry)
const result = context.declarations.filter(m => (m.kind === 'object' || m.kind === 'array' || m.kind === 'union') && m.entry)
.map(m => ({
entry: (m as ObjectDeclaration | ArrayDeclaration | UnionDeclaration).entry,
schema: {
$ref: `#/definitions/${m.name}`,
definitions: getReferencedDefinitions(m.name, definitions, [])
}
}))
if (result.length === 0) {
console.warn('No json schema generated because no @entry found.')
}
return result
}

export function getAllDefinitions(context: Context) {
Expand Down

0 comments on commit c4e2c51

Please sign in to comment.