Skip to content

Commit a895d41

Browse files
authored
Merge pull request #3 from JaredAAT/deal-with-default-values
Deal with default values
2 parents ff05ac3 + dbcd718 commit a895d41

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Convertor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class Convertor {
6969
obj.nullable = true
7070
} else {
7171
obj.type = type
72+
if (schema?.default) {
73+
obj.default = schema.default
74+
delete schema.default
75+
}
76+
7277
for (const property of Object.keys(schema)) {
7378
if (type === 'array' && property === 'items') {
7479
obj.items = schema[property]
@@ -110,7 +115,7 @@ class Convertor {
110115
}
111116

112117
if (schema.type === 'string') {
113-
if (Object.keys(schema).indexOf('default')) {
118+
if (Object.keys(schema).indexOf('default') !== -1) {
114119
schema.default = `${schema.default}`
115120
}
116121
}

test/schemas/complex-typeArray.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"errors": {
1111
"type": ["string", "null"],
1212
"description": "this is an errors object",
13-
"example": "Error occured here"
13+
"example": "Error occured here",
14+
"default": "hello world"
1415
},
1516
"error": {
1617
"type": ["object", "null"],
@@ -36,6 +37,13 @@
3637
"type": "string"
3738
}
3839
}
40+
},
41+
"booleanThing": {
42+
"type": ["null", "boolean"],
43+
"default": "false"
44+
},
45+
"otherBooleanThing": {
46+
"type": "boolean"
3947
}
4048
}
4149
}

0 commit comments

Comments
 (0)