Skip to content

Commit c753ff0

Browse files
committed
Fix to convert "format:binary "to type:"file
1 parent fec6268 commit c753ff0

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

libV2/schemaUtils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,11 @@ let QUERYPARAM = 'query',
479479
* @param {Object} context - Global context
480480
* @param {Object} schema - Schema that is to be resolved
481481
* @param {Number} [stack] - Current recursion depth
482-
* @param {String} resolveFor - For which action this resoltion is to be done
482+
* @param {String} resolveFor - For which action this resolution is to be done
483483
* @param {Object} seenRef - Map of all the references that have been resolved
484484
* @todo: Explore using a directed graph/tree for maintaining seen ref
485485
*
486-
* @returns {Object} Returns the object that staisfies the schema
486+
* @returns {Object} Returns the object that satisfies the schema
487487
*/
488488
resolveSchema = (context, schema, stack = 0, resolveFor = CONVERSION, seenRef = {}) => {
489489
if (!schema) {
@@ -576,6 +576,11 @@ let QUERYPARAM = 'query',
576576
return;
577577
}
578578

579+
// Set type to binary
580+
if (property.format === 'binary') {
581+
property.type = 'binary';
582+
}
583+
579584
if (
580585
property.format === 'decimal' ||
581586
property.format === 'byte' ||
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "Form Data - Binary - OpenAPI 3.0",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/uploadImage": {
9+
"post": {
10+
"summary": "uploads an image",
11+
"description": "",
12+
"operationId": "uploadFile",
13+
"requestBody": {
14+
"required": true,
15+
"content": {
16+
"multipart/form-data": {
17+
"schema": {
18+
"properties": {
19+
"inputfile": {
20+
"type": "string",
21+
"format": "binary",
22+
"description": "The file to be uploaded."
23+
}
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"responses": {
30+
"200": {
31+
"description": "successful operation"
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}

test/unit/convertV2.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ const expect = require('chai').expect,
110110
multiExampleResponseCodeMatching =
111111
path.join(__dirname, VALID_OPENAPI_PATH, '/multiExampleResponseCodeMatching.json'),
112112
duplicateCollectionVars =
113-
path.join(__dirname, VALID_OPENAPI_PATH, '/duplicateCollectionVars.json');
113+
path.join(__dirname, VALID_OPENAPI_PATH, '/duplicateCollectionVars.json'),
114+
issue795 = path.join(__dirname, VALID_OPENAPI_PATH, '/form-binary-file.json');
114115

115116

116117
describe('The convert v2 Function', function() {
@@ -2819,4 +2820,25 @@ describe('The convert v2 Function', function() {
28192820
done();
28202821
});
28212822
});
2823+
2824+
it('[Github #795] Should properly convert format binary to form data', function (done) {
2825+
var openapi = fs.readFileSync(issue795, 'utf8'),
2826+
reqBody, formData;
2827+
Converter.convertV2({ type: 'string', data: openapi }, {
2828+
requestNameSource: 'Fallback',
2829+
indentCharacter: 'Space',
2830+
collapseFolders: true,
2831+
optimizeConversion: true,
2832+
parametersResolution: 'schema'
2833+
}, (err, conversionResult) => {
2834+
2835+
reqBody = conversionResult.output[0].data.item[0].item[0].request.body;
2836+
formData = reqBody.formdata[0];
2837+
2838+
expect(err).to.be.null;
2839+
expect(conversionResult.result).to.equal(true);
2840+
expect(formData.type).to.equal('file');
2841+
done();
2842+
});
2843+
});
28222844
});

0 commit comments

Comments
 (0)