Skip to content

Commit

Permalink
fix: validateOutput() when schema contains internal reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mtjandra committed Aug 18, 2023
1 parent 2875a58 commit e88d210
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 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,45 @@ 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 +253,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 e88d210

Please sign in to comment.