Skip to content

Commit 81b8581

Browse files
committed
fix oneOf child no type
1 parent bdfeadb commit 81b8581

File tree

6 files changed

+869
-3
lines changed

6 files changed

+869
-3
lines changed

lib/deref.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const _ = require('lodash'),
2828
'double'
2929
],
3030
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
31-
traverseUtility = require('traverse');
31+
traverseUtility = require('traverse'),
32+
PROPERTIES_TO_ASSIGN_ON_CASCADE = ['type', 'nullable'];
3233

3334
/**
3435
* @param {*} currentNode - the object from which you're trying to find references
@@ -171,6 +172,11 @@ module.exports = {
171172
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
172173
}
173174
return { anyOf: _.map(schema.anyOf, (schemaElement) => {
175+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
176+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
177+
schemaElement[prop] = schema[prop];
178+
}
179+
});
174180
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
175181
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
176182
}) };
@@ -181,8 +187,14 @@ module.exports = {
181187
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
182188
}
183189
return { oneOf: _.map(schema.oneOf, (schemaElement) => {
184-
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
185-
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
190+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
191+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
192+
schemaElement[prop] = schema[prop];
193+
}
194+
});
195+
196+
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache,
197+
resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
186198
}) };
187199
}
188200
if (schema.allOf) {
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "How many items to return at one time (max 100)",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"format": "int32"
32+
}
33+
}
34+
],
35+
"responses": {
36+
"200": {
37+
"description": "A paged array of pets",
38+
"headers": {
39+
"x-next": {
40+
"description": "A link to the next page of responses",
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
},
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"$ref": "#/components/schemas/Pets"
50+
}
51+
}
52+
}
53+
},
54+
"default": {
55+
"description": "unexpected error",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"$ref": "#/components/schemas/Error"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"post": {
67+
"summary": "Create a pet",
68+
"operationId": "createPets",
69+
"tags": [
70+
"pets"
71+
],
72+
"responses": {
73+
"201": {
74+
"description": "Null response"
75+
},
76+
"default": {
77+
"description": "unexpected error",
78+
"content": {
79+
"application/json": {
80+
"schema": {
81+
"$ref": "#/components/schemas/Error"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
},
89+
"/pets/{petId}": {
90+
"get": {
91+
"summary": "Info for a specific pet",
92+
"operationId": "showPetById",
93+
"tags": [
94+
"pets"
95+
],
96+
"parameters": [
97+
{
98+
"name": "petId",
99+
"in": "path",
100+
"required": true,
101+
"description": "The id of the pet to retrieve",
102+
"schema": {
103+
"type": "string"
104+
}
105+
}
106+
],
107+
"responses": {
108+
"200": {
109+
"description": "Expected response to a valid request",
110+
"content": {
111+
"application/json": {
112+
"schema": {
113+
"$ref": "#/components/schemas/Pet"
114+
}
115+
}
116+
}
117+
},
118+
"default": {
119+
"description": "unexpected error",
120+
"content": {
121+
"application/json": {
122+
"schema": {
123+
"$ref": "#/components/schemas/Error"
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
},
132+
"components": {
133+
"schemas": {
134+
"Pet": {
135+
"type": "object",
136+
"required": [
137+
"id",
138+
"name"
139+
],
140+
"properties": {
141+
"id": {
142+
"type": "integer",
143+
"format": "int64"
144+
},
145+
"name": {
146+
"type": "string"
147+
},
148+
"actualDelivery": {
149+
"type": "string",
150+
"nullable": true,
151+
"oneOf": [
152+
{
153+
"enum": [
154+
""
155+
]
156+
},
157+
{
158+
"format": "date-time",
159+
"pattern": "^\\d{4}-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12]\\d)(T| )(2[0-3]|[01][0-9]):[0-5]\\d(|(:[0-5]\\dZ?)|(:[0-5]\\d\\.\\d{3})|(:[0-5]\\d\\.\\d{3}[+-]\\d{2}:\\d{2}))$"
160+
}
161+
]
162+
}
163+
}
164+
},
165+
"Pets": {
166+
"type": "array",
167+
"items": {
168+
"$ref": "#/components/schemas/Pet"
169+
}
170+
},
171+
"Error": {
172+
"type": "object",
173+
"required": [
174+
"code",
175+
"message"
176+
],
177+
"properties": {
178+
"code": {
179+
"type": "integer",
180+
"format": "int32"
181+
},
182+
"message": {
183+
"type": "string"
184+
}
185+
}
186+
}
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)