Deref object in form data params

Dereference form data params
This commit is contained in:
Luis Tejeda
2022-06-24 12:39:27 -05:00
parent 6df66da0d6
commit a559161597
3 changed files with 54 additions and 1 deletions

View File

@@ -1820,6 +1820,10 @@ module.exports = {
bodyData = this.convertToPmBodyData(contentObj[FORM_DATA], requestType, FORM_DATA,
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
encoding = contentObj[FORM_DATA].encoding ? contentObj[FORM_DATA].encoding : {};
if (contentObj[FORM_DATA].hasOwnProperty('schema') && contentObj[FORM_DATA].schema.hasOwnProperty('$ref')) {
contentObj[FORM_DATA].schema = this.getRefObject(contentObj[FORM_DATA].schema.$ref, components, options);
}
// create the form parameters and add it to the request body object
_.forOwn(bodyData, (value, key) => {

View File

@@ -0,0 +1,33 @@
openapi: 3.0.1
info:
title: My REST API
version: 1.0.0
paths:
/description-test:
post:
description: Endpoint description
operationId: description-test
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/RequestSchema'
responses:
"201":
description: Response description
content:
application/json;charset=UTF-8:
schema:
type: object
properties:
responseParam:
type: string
description: Response param description
components:
schemas:
RequestSchema:
type: object
properties:
requestParam:
type: string
description: Request param description

View File

@@ -50,7 +50,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml');
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
formDataParamDescription = path.join(__dirname, VALID_OPENAPI_PATH, '/form_data_param_description.yaml');
it('Should add collection level auth with type as `bearer`' +
@@ -1141,6 +1142,21 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});
it('[Github #559]Should convert description in form data parameters' +
petstoreParamExample, function(done) {
var openapi = fs.readFileSync(formDataParamDescription, 'utf8');
Converter.convert({ type: 'string', data: openapi },
{ }, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].description)
.to.equal('Request param description');
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].key).to.equal('requestParam');
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].value).to.equal('<string>');
done();
});
});
});
describe('Converting swagger 2.0 files', function() {
it('should convert path paramters to postman-compatible paramters', function (done) {