Skip to content

Commit

Permalink
fix: missing enum type reference
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkyao committed Nov 12, 2018
1 parent 472b401 commit d79d540
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions demo/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,24 @@
],
"additionalProperties": false
},
"StringEnum": {
"enum": [
"enum member 1",
"enum member 2"
]
},
"NumberEnum": {
"enum": [
0,
1
]
},
"NumberEnum2": {
"enum": [
3,
4
]
},
"StringType": {
"type": "object",
"properties": {
Expand Down
12 changes: 12 additions & 0 deletions src/json-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ export function generateJsonSchemas(typeDeclarations: TypeDeclaration[]) {
type: undefined,
$ref: `#/definitions/${typeDeclaration.name}`
}
} else if (typeDeclaration.kind === 'enum') {
if (typeDeclaration.members.length === 1) {
definitions[typeDeclaration.name] = {
type: undefined,
const: typeDeclaration.members[0]
}
} else {
definitions[typeDeclaration.name] = {
type: undefined,
enum: typeDeclaration.members.map((m) => m.value)
}
}
}
}
return typeDeclarations.filter(m => (m.kind === 'object' || m.kind === 'array' || m.kind === 'union') && m.entry)
Expand Down

0 comments on commit d79d540

Please sign in to comment.