Skip to content

Commit e0be1e3

Browse files
authored
fix: edge case where invalid parameter locks up normalizer (#1298)
1 parent 32c9241 commit e0be1e3

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export function normalizeSwagger(parsedSpec) {
205205
return (opParam.name && opParam.name === param.name)
206206
|| (opParam.$ref && opParam.$ref === param.$ref)
207207
|| (opParam.$$ref && opParam.$$ref === param.$$ref)
208+
|| (opParam === param)
208209
})
209210

210211
if (!exists) {

test/bugs/ui-4466.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,103 @@ it('should resolve test case from UI-4466 and UI-4467 correctly', async function
120120
}
121121
})
122122
})
123+
124+
it('should resolve modified test case where parameter is badly formatted', async function () {
125+
const invalidSpec = {
126+
swagger: '2.0',
127+
info: {
128+
version: 'v1',
129+
title: 'Foo'
130+
},
131+
basePath: '/v1/foo',
132+
produces: [
133+
'application/json'
134+
],
135+
parameters: {
136+
testHeader: {
137+
name: 'test-header',
138+
description: 'some request header',
139+
type: 'string',
140+
in: 'header',
141+
required: false
142+
}
143+
},
144+
paths: {
145+
'/': {
146+
parameters: [
147+
{}
148+
],
149+
get: {
150+
responses: {
151+
200: {
152+
description: 'Successful response',
153+
schema: {
154+
type: 'object',
155+
properties: {
156+
bar: {
157+
type: 'string'
158+
}
159+
}
160+
}
161+
}
162+
}
163+
}
164+
}
165+
}
166+
}
167+
168+
const res = await resolveSubtree(invalidSpec, [])
169+
170+
expect(res).toEqual({
171+
errors: [],
172+
spec: {
173+
swagger: '2.0',
174+
$$normalized: true,
175+
basePath: '/v1/foo',
176+
info: {
177+
title: 'Foo',
178+
version: 'v1',
179+
},
180+
parameters: {
181+
testHeader: {
182+
description: 'some request header',
183+
in: 'header',
184+
name: 'test-header',
185+
required: false,
186+
type: 'string',
187+
},
188+
},
189+
paths: {
190+
'/': {
191+
get: {
192+
parameters: [
193+
{},
194+
],
195+
produces: [
196+
'application/json',
197+
],
198+
responses: {
199+
200: {
200+
description: 'Successful response',
201+
schema: {
202+
properties: {
203+
bar: {
204+
type: 'string',
205+
},
206+
},
207+
type: 'object',
208+
},
209+
},
210+
},
211+
},
212+
parameters: [
213+
{},
214+
],
215+
},
216+
},
217+
produces: [
218+
'application/json',
219+
]
220+
}
221+
})
222+
})

0 commit comments

Comments
 (0)