Skip to content

Commit 784f8f3

Browse files
authored
Merge pull request #4 from JaredAAT/deal-with-default-value-outside-of-ofProperty
Deal with default value outside of of property
2 parents a895d41 + 1a0bdfb commit 784f8f3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Convertor.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,28 @@ class Convertor {
121121
}
122122
}
123123

124+
const defaultValuesForOfProperties = () => {
125+
if (schema.type === undefined && this.ofProperties.some(element => Object.keys(schema).includes(element))) {
126+
if (Object.keys(schema).includes('default')) {
127+
for (const property of this.ofProperties) {
128+
if (Object.keys(schema).includes(property)) {
129+
for (const ofProperty of schema[property]) {
130+
if (ofProperty.type !== 'null' || ofProperty.nullable) {
131+
ofProperty.default = schema.default
132+
delete schema.default
133+
}
134+
}
135+
}
136+
}
137+
}
138+
}
139+
}
140+
124141
convertNull()
125142
convertTypeArrays()
126143
bannedWordsRemoval()
127144
convertDefaultValues()
145+
defaultValuesForOfProperties()
128146

129147
if (this.specialProperties.indexOf(parentKeyword) !== -1) {
130148
if (this.ofProperties.indexOf(parentKeyword) !== -1) {

test/schemas/complex-typeArray.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@
4444
},
4545
"otherBooleanThing": {
4646
"type": "boolean"
47+
},
48+
"mode": {
49+
"anyOf": [
50+
{
51+
"type": "null"
52+
},
53+
{
54+
"type": "string",
55+
"enum": ["header", "parameter", "cookie"],
56+
"default": "header"
57+
}
58+
],
59+
"description": "From which part of the request the token should be extracted. Possible values are 'header', 'parameter', 'cookie'.",
60+
"default": "header"
4761
}
4862
}
4963
}

0 commit comments

Comments
 (0)