Skip to content

Commit 6eee43a

Browse files
committed
Avoiding to set type as object when property's schema is an empty object
1 parent 72f2a10 commit 6eee43a

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
@@ -256,8 +256,10 @@ module.exports = {
256256
continue;
257257
}
258258
/* eslint-enable */
259-
tempSchema.properties[prop] = this.resolveRefs(property, parameterSourceOption, components,
260-
schemaResolutionCache, resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
259+
tempSchema.properties[prop] = _.isEmpty(property) ?
260+
{} :
261+
this.resolveRefs(property, parameterSourceOption, components,
262+
schemaResolutionCache, resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
261263
}
262264
}
263265
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
@@ -1367,6 +1367,30 @@ describe('CONVERT FUNCTION TESTS ', function() {
13671367
done();
13681368
});
13691369
});
1370+
1371+
it('[GITHUB #10710] - should convert file with all of merging properties. ' +
1372+
'One ocurrence is an empty object and the other is a boolean type', function() {
1373+
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_YAML, 'allOfConflicted.yaml'),
1374+
fileData = fs.readFileSync(fileSource, 'utf8'),
1375+
input = {
1376+
type: 'string',
1377+
data: fileData
1378+
};
1379+
1380+
Converter.convert(input, { optimizeConversion: false, stackLimit: 50 }, (err, result) => {
1381+
const expectedResponseBody1 = JSON.parse(
1382+
result.output[0].data.item[0].item[0].response[0].body
1383+
),
1384+
expectedResponseBody2 = JSON.parse(
1385+
result.output[0].data.item[0].item[1].response[0].body
1386+
);
1387+
expect(err).to.be.null;
1388+
expect(result.result).to.be.true;
1389+
expect(expectedResponseBody1.payload).to.be.a('boolean');
1390+
expect(expectedResponseBody2.payload).to.be.an('object')
1391+
.and.to.have.all.keys('content', 'paging');
1392+
});
1393+
});
13701394
});
13711395

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

0 commit comments

Comments
 (0)