Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bugs": "https://github.com/stoplightio/prism/issues",
"dependencies": {
"@stoplight/json": "^3.18.1",
"@stoplight/json-schema-ref-parser": "9.2.7",
"@stoplight/json-schema-ref-parser": "10.0.0",
"@stoplight/prism-core": "^5.8.0",
"@stoplight/prism-http": "^5.8.1",
"@stoplight/prism-http-server": "^5.8.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@stoplight/json-schema-sampler": "0.3.0",
"@stoplight/prism-core": "^5.8.0",
"@stoplight/http-spec": "^7.0.3",
"@stoplight/json-schema-ref-parser": "9.2.7",
"@stoplight/json-schema-ref-parser": "10.0.0",
"@stoplight/types": "^14.1.0",
"@stoplight/yaml": "^4.2.3",
"abstract-logging": "^2.0.1",
Expand Down
150 changes: 150 additions & 0 deletions packages/http/src/mocker/__tests__/HttpMocker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
],
},
],
};

Expand Down Expand Up @@ -676,5 +689,142 @@ describe('mocker', () => {
});
});
});

describe('should return 500 error', () => {
Copy link
Contributor

@brendarearden brendarearden Jun 24, 2024

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?

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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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),
});
});
});
});
});
});
2 changes: 1 addition & 1 deletion packages/http/src/mocker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const mock: IPrismComponents<IHttpOperation, IHttpRequest, IHttpResponse, IHttpM
config,
}) => {
const payloadGenerator: PayloadGenerator = config.dynamic
? partial(generate, resource, resource['__bundle__'])
? partial(generate, resource, resource['__bundled__'])
: partial(generateStatic, resource);

return pipe(
Expand Down
Loading