Skip to content

Commit

Permalink
fix: validateOutput() when schema contains internal reference (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtjandra authored Aug 25, 2023
1 parent 58ad3b1 commit 8e143e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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

0 comments on commit 8e143e6

Please sign in to comment.