Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 3d914af

Browse files
author
Dom Harrington
committed
Fix bug in oas-to-har when $ref lookup is required
1 parent 9c6b00b commit 3d914af

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/api-explorer/__tests__/lib/oas-to-har.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,26 @@ describe('body values', () => {
580580
).log.entries[0].request.postData.text,
581581
).toEqual(JSON.stringify({}));
582582
});
583+
584+
it('should work for schemas that require a lookup', () => {
585+
expect(
586+
oasToHar(
587+
{
588+
components: {
589+
requestBodies: { schema: { content: { 'application/json': { schema: { type: 'object', properties: { a: { type: 'integer' } } } } } } },
590+
},
591+
},
592+
{
593+
path: '/body',
594+
method: 'get',
595+
requestBody: {
596+
$ref: '#/components/requestBodies/schema'
597+
},
598+
},
599+
{ body: { a: 123 } },
600+
).log.entries[0].request.postData.text,
601+
).toEqual(JSON.stringify({ a: 123 }));
602+
});
583603
});
584604

585605
describe('formData values', () => {

packages/api-explorer/src/lib/oas-to-har.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ module.exports = (
147147
});
148148
}
149149

150-
const schema = getSchema(pathOperation) || { schema: {} };
150+
const schema = getSchema(pathOperation, oas) || { schema: {} };
151151

152152
if (schema.schema && Object.keys(schema.schema).length) {
153153
// If there is formData, then the type is application/x-www-form-urlencoded

0 commit comments

Comments
 (0)