-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: circular reference issue resolved #2538
Changes from all commits
e6f1ac8
b2b0f89
d34584d
23d8df8
8060af3
e3e9a6a
23bc796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,19 @@ describe('mocker', () => { | |
}, | ||
], | ||
}, | ||
{ | ||
id: '500', | ||
code: '500', | ||
headers: [], | ||
contents: [ | ||
{ | ||
id: 'contents', | ||
mediaType: 'application/json', | ||
examples: [{ id: 'example-1', key: 'internalServerError', value: { message: 'Internal Server Error' } }], | ||
encodings: [], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
|
@@ -676,5 +689,142 @@ describe('mocker', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('should return 500 error', () => { | ||
it('returns a 500 error response', () => { | ||
jest.spyOn(helpers, 'negotiateOptionsForInvalidRequest').mockReturnValue( | ||
right({ | ||
code: '500', | ||
mediaType: 'application/json', | ||
bodyExample: mockResource.responses[3].contents![0].examples![0], | ||
headers: [], | ||
}) | ||
); | ||
const mockResult = mock({ | ||
config: { dynamic: false }, | ||
resource: mockResource, | ||
input: Object.assign({}, mockInput, { | ||
validations: [{ severity: DiagnosticSeverity.Error }], | ||
}), | ||
})(logger); | ||
assertRight(mockResult, result => { | ||
expect(result).toMatchObject({ | ||
statusCode: 500, | ||
body: { message: 'Internal Server Error' }, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('With __bundled__ should get response', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is passing with and without your changes so it still doesn't seem to be testing the initial bug you were seeing / the fix hasn't changed anything. It should be removed or changed to properly capture the issue you are seeing and fixing. We have test harness tests for circular references and those have been passing in the pipeline so it seems like circular references are getting resolved in most cases. Maybe a test harness test for the specific scenario that is causing you not to see circular references get resolved would help demonstrate the issue a bit better. |
||
it('With __bundled__ should get response', () => { | ||
const BundledResource: IHttpOperation = { | ||
...mockResource, | ||
// @ts-ignore - Requires update in @stoplight/types to allow for '__bundled__' | ||
__bundled__: { | ||
properties: { | ||
id: { | ||
type: 'integer', | ||
description: 'Unique identifier for the given user.', | ||
}, | ||
name: { | ||
type: 'string', | ||
}, | ||
surname: { | ||
type: 'string', | ||
}, | ||
user: { | ||
title: 'User', | ||
type: 'object', | ||
examples: [ | ||
{ | ||
id: 142, | ||
name: 'Alice', | ||
surname: 'Smith', | ||
}, | ||
], | ||
required: ['id', 'name', 'surname'], | ||
properties: { | ||
$ref: '#/__bundled__/properties', | ||
}, | ||
}, | ||
test: { | ||
title: 'Test', | ||
type: 'object', | ||
properties: { | ||
id: { | ||
type: 'string', | ||
}, | ||
user: { | ||
title: 'User', | ||
type: 'object', | ||
examples: [ | ||
{ | ||
id: 142, | ||
name: 'Alice', | ||
surname: 'Smith', | ||
}, | ||
], | ||
required: ['id', 'name', 'surname'], | ||
properties: { | ||
$ref: '#/__bundled__/properties', | ||
}, | ||
}, | ||
test: { | ||
title: 'Test', | ||
type: 'object', | ||
properties: { | ||
$ref: '#/__bundled__/properties_2', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
properties_2: { | ||
id: { | ||
type: 'string', | ||
}, | ||
user: { | ||
title: 'User', | ||
type: 'object', | ||
examples: [ | ||
{ | ||
id: 142, | ||
name: 'Alice', | ||
surname: 'Smith', | ||
}, | ||
], | ||
required: ['id', 'name', 'surname'], | ||
properties: { | ||
$ref: '#/__bundled__/properties', | ||
}, | ||
}, | ||
test: { | ||
title: 'Test', | ||
type: 'object', | ||
properties: { | ||
$ref: '#/__bundled__/properties_2', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockResult = mock({ | ||
config: { dynamic: true }, | ||
resource: BundledResource, | ||
input: mockInput, | ||
})(logger); | ||
assertRight(mockResult, result => { | ||
expect(result).toMatchObject({ | ||
statusCode: 200, | ||
}); | ||
expect(result).toHaveProperty('body', { | ||
name: expect.any(String), | ||
surname: expect.any(String), | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test does not seem relevant to this PR. Could you please add a test that covers the original circular reference problem and show that it is no longer throwing a 500?