Skip to content

Commit c4c5ea3

Browse files
authored
Merge pull request #571 from postmanlabs/fix/559-parameterDescriptionFormData
Deref object in form data params
2 parents 682eb77 + ee449b7 commit c4c5ea3

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

lib/schemaUtils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,10 @@ module.exports = {
18271827
bodyData = this.convertToPmBodyData(contentObj[FORM_DATA], requestType, FORM_DATA,
18281828
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
18291829
encoding = contentObj[FORM_DATA].encoding ? contentObj[FORM_DATA].encoding : {};
1830+
1831+
if (contentObj[FORM_DATA].hasOwnProperty('schema') && contentObj[FORM_DATA].schema.hasOwnProperty('$ref')) {
1832+
contentObj[FORM_DATA].schema = this.getRefObject(contentObj[FORM_DATA].schema.$ref, components, options);
1833+
}
18301834
// create the form parameters and add it to the request body object
18311835
_.forOwn(bodyData, (value, key) => {
18321836

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.1
2+
info:
3+
title: My REST API
4+
version: 1.0.0
5+
paths:
6+
/description-test:
7+
post:
8+
description: Endpoint description
9+
operationId: description-test
10+
requestBody:
11+
content:
12+
multipart/form-data:
13+
schema:
14+
$ref: '#/components/schemas/RequestSchema'
15+
responses:
16+
"201":
17+
description: Response description
18+
content:
19+
application/json;charset=UTF-8:
20+
schema:
21+
type: object
22+
properties:
23+
responseParam:
24+
type: string
25+
description: Response param description
26+
components:
27+
schemas:
28+
RequestSchema:
29+
type: object
30+
properties:
31+
requestParam:
32+
type: string
33+
description: Request param description

test/unit/base.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
5151
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
5252
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
5353
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
54+
formDataParamDescription = path.join(__dirname, VALID_OPENAPI_PATH, '/form_data_param_description.yaml'),
5455
allHTTPMethodsSpec = path.join(__dirname, VALID_OPENAPI_PATH, '/all-http-methods.yaml');
5556

5657

@@ -1143,6 +1144,21 @@ describe('CONVERT FUNCTION TESTS ', function() {
11431144
});
11441145
});
11451146

1147+
it('[Github #559]Should convert description in form data parameters' +
1148+
petstoreParamExample, function(done) {
1149+
var openapi = fs.readFileSync(formDataParamDescription, 'utf8');
1150+
Converter.convert({ type: 'string', data: openapi },
1151+
{ }, (err, conversionResult) => {
1152+
expect(err).to.be.null;
1153+
expect(conversionResult.result).to.equal(true);
1154+
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].description)
1155+
.to.equal('Request param description');
1156+
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].key).to.equal('requestParam');
1157+
expect(conversionResult.output[0].data.item[0].request.body.formdata[0].value).to.equal('<string>');
1158+
done();
1159+
});
1160+
});
1161+
11461162
it('Should have disableBodyPruning option for protocolProfileBehavior set to true for all types of request' +
11471163
allHTTPMethodsSpec, function (done) {
11481164
var openapi = fs.readFileSync(allHTTPMethodsSpec, 'utf8');
@@ -1155,11 +1171,11 @@ describe('CONVERT FUNCTION TESTS ', function() {
11551171
_.forEach(conversionResult.output[0].data.item[0].item, (request) => {
11561172
expect(request.protocolProfileBehavior.disableBodyPruning).to.eql(true);
11571173
});
1158-
11591174
done();
11601175
});
11611176
});
11621177
});
1178+
11631179
describe('Converting swagger 2.0 files', function() {
11641180
it('should convert path paramters to postman-compatible paramters', function (done) {
11651181
const fileData = path.join(__dirname, SWAGGER_20_FOLDER_JSON, 'swagger2-with-params.json'),

0 commit comments

Comments
 (0)