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: validateOutput() when schema contains internal reference #2363

Merged
Merged
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
46 changes: 46 additions & 0 deletions packages/http/src/validator/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,51 @@ describe('HttpValidator', () => {
});

describe('validateOutput()', () => {
describe('when schema contains an internal reference', () => {
it('validates response correctly', () => {
assertLeft(
validator.validateOutput({
resource: {
method: 'get',
path: '/',
id: '1',
request: {},
// @ts-ignore - Requires update in @stoplight/types to allow for '__bundled__'
__bundled__: { OutputType: { type: 'string' } },
responses: [
{
id: faker.random.word(),
code: '200',
contents: [
{
id: faker.random.word(),
mediaType: 'application/json',
schema: {
type: 'object',
properties: { output: { $ref: '#/__bundled__/OutputType' } },
required: ['output'],
},
},
],
},
],
},
element: { statusCode: 200, headers: { 'content-type': 'application/json' }, body: {} },
}),
error => {
expect(error).toEqual([
{
code: 'required',
message: "Response body must have required property 'output'",
path: ['body'],
severity: 0,
},
]);
}
);
});
});

describe('output is set', () => {
beforeAll(() => {
jest.spyOn(validators, 'validateBody').mockReturnValue(E.left([mockError]));
Expand Down Expand Up @@ -214,6 +259,7 @@ describe('HttpValidator', () => {
[],
ValidationContext.Output,
undefined,
undefined,
undefined
);
expect(validators.validateHeaders).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/http/src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const validateOutput: ValidatorFn<IHttpOperation, IHttpResponse> = ({ res
contents => validateMediaType(contents, mediaType)
)
),
validateBody(element.body, response.contents || [], ValidationContext.Output, mediaType, bundle),
validateBody(element.body, response.contents || [], ValidationContext.Output, mediaType, undefined, bundle),
validateHeaders(element.headers || {}, response.headers || [], ValidationContext.Output, bundle)
)
),
Expand Down