-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deep-extend does not support array merge. There was special code added to merge top-level arrays, but that was a shallow merge. Use deepmerge instead of deep-extend to merge arrays also. Default merge settings seem to work well - all tests pass. Add a test case based on swagger-api/swagger-ui#7618 Fixes: 2f5bb86 ("Fix and test for swagger-ui #3328: swagger-api/swagger-ui#3328. Added manual logic to merge arrays after calling deepExtend within `mergeDeep` function")
- Loading branch information
Showing
3 changed files
with
221 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
// https://github.com/swagger-api/swagger-ui/issues/7618 | ||
|
||
import resolveSubtree from '../../src/subtree-resolver/index.js'; | ||
|
||
const spec = { | ||
openapi: '3.0.3', | ||
info: { | ||
version: '1.0.0', | ||
title: 'test', | ||
description: 'test', | ||
contact: { | ||
name: 'test', | ||
email: '[email protected]', | ||
}, | ||
}, | ||
servers: [ | ||
{ | ||
url: 'https://localhost/api', | ||
}, | ||
], | ||
tags: [ | ||
{ | ||
name: 'Test', | ||
description: 'Test', | ||
}, | ||
], | ||
paths: { | ||
'/one': { | ||
get: { | ||
description: 'test', | ||
operationId: 'one', | ||
tags: ['Test'], | ||
parameters: [ | ||
{ | ||
name: 'test', | ||
in: 'header', | ||
required: true, | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
], | ||
responses: { | ||
default: { | ||
description: 'Response', | ||
content: { | ||
'text/plain': { | ||
schema: { | ||
type: 'integer', | ||
enum: [401, 404, 500], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
parent: { | ||
type: 'object', | ||
required: ['required1'], | ||
properties: { | ||
required1: { | ||
type: 'string', | ||
}, | ||
nested1: { | ||
type: 'object', | ||
required: ['nestedrequired1'], | ||
properties: { | ||
nestedrequired1: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
child: { | ||
allOf: [ | ||
{ | ||
$ref: '#/components/schemas/parent', | ||
}, | ||
{ | ||
type: 'object', | ||
required: ['required2'], | ||
properties: { | ||
required2: { | ||
type: 'string', | ||
}, | ||
nested1: { | ||
type: 'object', | ||
required: ['nestedrequired2'], | ||
properties: { | ||
nestedrequired2: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
test('should resolve test case from UI-7618 correctly', async () => { | ||
const res = await resolveSubtree(spec, []); | ||
|
||
expect(res).toEqual({ | ||
spec: { | ||
openapi: '3.0.3', | ||
info: { | ||
version: '1.0.0', | ||
title: 'test', | ||
description: 'test', | ||
contact: { | ||
name: 'test', | ||
email: '[email protected]', | ||
}, | ||
}, | ||
servers: [ | ||
{ | ||
url: 'https://localhost/api', | ||
}, | ||
], | ||
tags: [ | ||
{ | ||
name: 'Test', | ||
description: 'Test', | ||
}, | ||
], | ||
paths: { | ||
'/one': { | ||
get: { | ||
description: 'test', | ||
operationId: 'one', | ||
tags: ['Test'], | ||
parameters: [ | ||
{ | ||
name: 'test', | ||
in: 'header', | ||
required: true, | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
], | ||
responses: { | ||
default: { | ||
description: 'Response', | ||
content: { | ||
'text/plain': { | ||
schema: { | ||
type: 'integer', | ||
enum: [401, 404, 500], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
__originalOperationId: 'one', | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
parent: { | ||
type: 'object', | ||
required: ['required1'], | ||
properties: { | ||
required1: { | ||
type: 'string', | ||
}, | ||
nested1: { | ||
type: 'object', | ||
required: ['nestedrequired1'], | ||
properties: { | ||
nestedrequired1: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
child: { | ||
type: 'object', | ||
required: ['required1', 'required2'], | ||
properties: { | ||
required1: { | ||
type: 'string', | ||
}, | ||
nested1: { | ||
type: 'object', | ||
required: ['nestedrequired1', 'nestedrequired2'], | ||
properties: { | ||
nestedrequired1: { | ||
type: 'string', | ||
}, | ||
nestedrequired2: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
required2: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
$$normalized: true, | ||
}, | ||
errors: [], | ||
}); | ||
}); |