Skip to content

Commit 949c077

Browse files
committed
convert default values
1 parent c961863 commit 949c077

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Convertor.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,37 @@ class Convertor {
8989
}
9090
}
9191

92+
const convertDefaultValues = () => {
93+
if (schema.type === 'boolean') {
94+
if (schema.default === 'true' || schema.default === 'false') {
95+
if (schema.default === 'true')
96+
schema.default = true
97+
else
98+
schema.default = false
99+
}
100+
}
101+
102+
if (schema.type === 'number' || schema.type === 'integer') {
103+
if (typeof schema.default === 'string') {
104+
schema.default = parseInt(schema.default, 10)
105+
}
106+
}
107+
108+
if (schema.type === 'array' && schema.items === undefined) {
109+
schema.items = {nullable: true}
110+
}
111+
112+
if (schema.type === 'string') {
113+
if (Object.keys(schema).indexOf('default')) {
114+
schema.default = `${schema.default}`
115+
}
116+
}
117+
}
118+
92119
convertNull()
93120
convertTypeArrays()
94121
bannedWordsRemoval()
122+
convertDefaultValues()
95123

96124
if (this.specialProperties.indexOf(parentKeyword) !== -1) {
97125
if (this.ofProperties.indexOf(parentKeyword) !== -1) {

0 commit comments

Comments
 (0)