Skip to content

Commit 0e6ce7c

Browse files
Merge pull request #613 from postmanlabs/fix/mergeEmptyBodyWithDifferentInAllOf#10710
Avoiding to set type as object when property's schema is an empty object
2 parents 70b42f9 + 6eee43a commit 0e6ce7c

File tree

3 files changed

+188
-2
lines changed

3 files changed

+188
-2
lines changed

lib/deref.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ module.exports = {
281281
continue;
282282
}
283283
/* eslint-enable */
284-
tempSchema.properties[prop] = this.resolveRefs(property, parameterSourceOption, components,
285-
schemaResolutionCache, resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
284+
tempSchema.properties[prop] = _.isEmpty(property) ?
285+
{} :
286+
this.resolveRefs(property, parameterSourceOption, components,
287+
schemaResolutionCache, resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
286288
}
287289
}
288290
return tempSchema;
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
basePath: /api/v1
2+
definitions:
3+
comm.TestGroupRequest:
4+
properties:
5+
groupNm:
6+
type: string
7+
user:
8+
$ref: '#/definitions/user.User'
9+
type: object
10+
comm.TestGroupResponse:
11+
properties:
12+
groupCode:
13+
type: integer
14+
type: object
15+
comm.TestRequest:
16+
properties:
17+
codeNm:
18+
type: string
19+
user:
20+
$ref: '#/definitions/user.User'
21+
type: object
22+
comm.TestResponse:
23+
properties:
24+
testCode:
25+
type: string
26+
creDate:
27+
type: string
28+
creId:
29+
type: string
30+
type: object
31+
comm.Request:
32+
properties:
33+
user:
34+
$ref: '#/definitions/user.User'
35+
type: object
36+
pagination.Page:
37+
properties:
38+
limit:
39+
type: integer
40+
next_page:
41+
type: integer
42+
offset:
43+
type: integer
44+
page:
45+
type: integer
46+
prev_page:
47+
type: integer
48+
total_page:
49+
type: integer
50+
total_record:
51+
type: integer
52+
type: object
53+
pagination.Paginator:
54+
properties:
55+
content: {}
56+
paging:
57+
$ref: '#/definitions/pagination.Page'
58+
type: object
59+
response.Header:
60+
properties:
61+
resultCode:
62+
type: string
63+
resultMessage:
64+
type: string
65+
success:
66+
type: boolean
67+
type: object
68+
response.Response:
69+
properties:
70+
header:
71+
$ref: '#/definitions/response.Header'
72+
payload: {}
73+
type: object
74+
user.User:
75+
properties:
76+
userId:
77+
type: string
78+
type: object
79+
info:
80+
contact: {}
81+
description: test
82+
license:
83+
name: Apache 2.0
84+
url: http://www.apache.org/licenses/LICENSE-2.0.html
85+
termsOfService: http://swagger.io/terms/
86+
title: TEST API
87+
version: "1.0"
88+
paths:
89+
/comm/test/duplicate/{id}:
90+
get:
91+
consumes:
92+
- application/json
93+
description: duplicate check
94+
parameters:
95+
- description: id
96+
in: path
97+
name: id
98+
required: true
99+
type: string
100+
produces:
101+
- application/json
102+
responses:
103+
"200":
104+
description: OK
105+
schema:
106+
allOf:
107+
- $ref: '#/definitions/response.Response'
108+
- properties:
109+
payload:
110+
type: boolean
111+
type: object
112+
security:
113+
- ApiKeyAuth: []
114+
summary: duplicate check
115+
tags:
116+
- test1
117+
/comm/test/page:
118+
get:
119+
consumes:
120+
- application/json
121+
description: list (paging)
122+
parameters:
123+
- description: page
124+
in: query
125+
name: page
126+
type: integer
127+
- description: limit
128+
in: query
129+
name: pageSize
130+
type: integer
131+
produces:
132+
- application/json
133+
responses:
134+
"200":
135+
description: OK
136+
schema:
137+
allOf:
138+
- $ref: '#/definitions/response.Response'
139+
- properties:
140+
payload:
141+
allOf:
142+
- $ref: '#/definitions/pagination.Paginator'
143+
- properties:
144+
content:
145+
items:
146+
$ref: '#/definitions/comm.TestResponse'
147+
type: array
148+
type: object
149+
type: object
150+
security:
151+
- ApiKeyAuth: []
152+
summary: list
153+
tags:
154+
- test2
155+
securityDefinitions:
156+
ApiKeyAuth:
157+
in: header
158+
name: Authorization
159+
type: apiKey
160+
swagger: "2.0"

test/unit/base.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,30 @@ describe('CONVERT FUNCTION TESTS ', function() {
13911391
done();
13921392
});
13931393
});
1394+
1395+
it('[GITHUB #10710] - should convert file with all of merging properties. ' +
1396+
'One ocurrence is an empty object and the other is a boolean type', function() {
1397+
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_YAML, 'allOfConflicted.yaml'),
1398+
fileData = fs.readFileSync(fileSource, 'utf8'),
1399+
input = {
1400+
type: 'string',
1401+
data: fileData
1402+
};
1403+
1404+
Converter.convert(input, { optimizeConversion: false, stackLimit: 50 }, (err, result) => {
1405+
const expectedResponseBody1 = JSON.parse(
1406+
result.output[0].data.item[0].item[0].response[0].body
1407+
),
1408+
expectedResponseBody2 = JSON.parse(
1409+
result.output[0].data.item[0].item[1].response[0].body
1410+
);
1411+
expect(err).to.be.null;
1412+
expect(result.result).to.be.true;
1413+
expect(expectedResponseBody1.payload).to.be.a('boolean');
1414+
expect(expectedResponseBody2.payload).to.be.an('object')
1415+
.and.to.have.all.keys('content', 'paging');
1416+
});
1417+
});
13941418
});
13951419

13961420
describe('requestNameSource option', function() {

0 commit comments

Comments
 (0)