Skip to content

Commit 32c9241

Browse files
authored
fix: normalization regression (#1297)
1 parent 3ec8f5e commit 32c9241

File tree

2 files changed

+125
-3
lines changed

2 files changed

+125
-3
lines changed

src/helpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ export function normalizeSwagger(parsedSpec) {
202202
else if (inheritName === 'parameters') {
203203
for (const param of inherits[inheritName]) {
204204
const exists = operation[inheritName].some((opParam) => {
205-
// check for `opParam.name` in case the parameter has
206-
// no name, which is important for $ref'd parameters
207-
return opParam.name && opParam.name === param.name
205+
return (opParam.name && opParam.name === param.name)
206+
|| (opParam.$ref && opParam.$ref === param.$ref)
207+
|| (opParam.$$ref && opParam.$$ref === param.$$ref)
208208
})
209209

210210
if (!exists) {

test/bugs/ui-4466.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// https://github.com/swagger-api/swagger-ui/issues/4466
2+
// https://github.com/swagger-api/swagger-ui/issues/4467
3+
4+
import expect, {createSpy, spyOn} from 'expect'
5+
import resolveSubtree from '../../src/subtree-resolver'
6+
7+
const spec = {
8+
swagger: '2.0',
9+
info: {
10+
version: 'v1',
11+
title: 'Foo'
12+
},
13+
basePath: '/v1/foo',
14+
produces: [
15+
'application/json'
16+
],
17+
parameters: {
18+
testHeader: {
19+
name: 'test-header',
20+
description: 'some request header',
21+
type: 'string',
22+
in: 'header',
23+
required: false
24+
}
25+
},
26+
paths: {
27+
'/': {
28+
parameters: [
29+
{
30+
$ref: '#/parameters/testHeader'
31+
}
32+
],
33+
get: {
34+
responses: {
35+
200: {
36+
description: 'Successful response',
37+
schema: {
38+
type: 'object',
39+
properties: {
40+
bar: {
41+
type: 'string'
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
53+
it('should resolve test case from UI-4466 and UI-4467 correctly', async function () {
54+
const res = await resolveSubtree(spec, [])
55+
56+
expect(res).toEqual({
57+
errors: [],
58+
spec: {
59+
swagger: '2.0',
60+
$$normalized: true,
61+
basePath: '/v1/foo',
62+
info: {
63+
title: 'Foo',
64+
version: 'v1',
65+
},
66+
parameters: {
67+
testHeader: {
68+
description: 'some request header',
69+
in: 'header',
70+
name: 'test-header',
71+
required: false,
72+
type: 'string',
73+
},
74+
},
75+
paths: {
76+
'/': {
77+
get: {
78+
parameters: [
79+
{
80+
$$ref: '#/parameters/testHeader',
81+
description: 'some request header',
82+
in: 'header',
83+
name: 'test-header',
84+
required: false,
85+
type: 'string',
86+
},
87+
],
88+
produces: [
89+
'application/json',
90+
],
91+
responses: {
92+
200: {
93+
description: 'Successful response',
94+
schema: {
95+
properties: {
96+
bar: {
97+
type: 'string',
98+
},
99+
},
100+
type: 'object',
101+
},
102+
},
103+
},
104+
},
105+
parameters: [
106+
{
107+
$$ref: '#/parameters/testHeader',
108+
description: 'some request header',
109+
in: 'header',
110+
name: 'test-header',
111+
required: false,
112+
type: 'string',
113+
},
114+
],
115+
},
116+
},
117+
produces: [
118+
'application/json',
119+
]
120+
}
121+
})
122+
})

0 commit comments

Comments
 (0)