Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to convert "format:binary" to "type:"file #805

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ let QUERYPARAM = 'query',
* @param {Object} context - Global context
* @param {Object} schema - Schema that is to be resolved
* @param {Number} [stack] - Current recursion depth
* @param {String} resolveFor - For which action this resoltion is to be done
* @param {String} resolveFor - For which action this resolution is to be done
* @param {Object} seenRef - Map of all the references that have been resolved
* @todo: Explore using a directed graph/tree for maintaining seen ref
*
* @returns {Object} Returns the object that staisfies the schema
* @returns {Object} Returns the object that satisfies the schema
*/
resolveSchema = (context, schema, stack = 0, resolveFor = CONVERSION, seenRef = {}) => {
if (!schema) {
Expand Down Expand Up @@ -576,6 +576,11 @@ let QUERYPARAM = 'query',
return;
}

// Set type to binary
if (property.format === 'binary') {
property.type = 'binary';
thim81 marked this conversation as resolved.
Show resolved Hide resolved
}

if (
property.format === 'decimal' ||
property.format === 'byte' ||
Expand Down
37 changes: 37 additions & 0 deletions test/data/valid_openapi/form-binary-file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"openapi": "3.0.3",
"info": {
"title": "Form Data - Binary - OpenAPI 3.0",
"version": "1.0.0"
},
"paths": {
"/uploadImage": {
"post": {
"summary": "uploads an image",
"description": "",
"operationId": "uploadFile",
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"inputfile": {
"type": "string",
"format": "binary",
"description": "The file to be uploaded."
}
}
}
}
}
},
"responses": {
"200": {
"description": "successful operation"
}
}
}
}
}
}
24 changes: 23 additions & 1 deletion test/unit/convertV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
multiExampleResponseCodeMatching =
path.join(__dirname, VALID_OPENAPI_PATH, '/multiExampleResponseCodeMatching.json'),
duplicateCollectionVars =
path.join(__dirname, VALID_OPENAPI_PATH, '/duplicateCollectionVars.json');
path.join(__dirname, VALID_OPENAPI_PATH, '/duplicateCollectionVars.json'),
issue795 = path.join(__dirname, VALID_OPENAPI_PATH, '/form-binary-file.json');


describe('The convert v2 Function', function() {
Expand Down Expand Up @@ -310,7 +311,7 @@
});

// Need to handle collaping of folders
it.skip('Should generate collection with collapsing unnecessary folders ' +

Check warning on line 314 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 314 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 314 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, {}, (err, conversionResult) => {
Expand All @@ -322,7 +323,7 @@
done();
});
});
it.skip('Should collapse child and parent folder when parent has only one child' +

Check warning on line 326 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 326 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 326 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec1, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec1, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
Expand All @@ -336,7 +337,7 @@
done();
});
});
it.skip('Should generate collection without creating folders and having only one request' +

Check warning on line 340 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (14.x)

Unexpected skipped mocha test

Check warning on line 340 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (16.x)

Unexpected skipped mocha test

Check warning on line 340 in test/unit/convertV2.test.js

View workflow job for this annotation

GitHub Actions / Unit-Tests (18.x)

Unexpected skipped mocha test
multipleFoldersSpec2, function(done) {
var openapi = fs.readFileSync(multipleFoldersSpec2, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
Expand Down Expand Up @@ -2819,4 +2820,25 @@
done();
});
});

it('[Github #795] Should properly convert format binary to form data', function (done) {
var openapi = fs.readFileSync(issue795, 'utf8'),
reqBody, formData;
Converter.convertV2({ type: 'string', data: openapi }, {
requestNameSource: 'Fallback',
indentCharacter: 'Space',
collapseFolders: true,
optimizeConversion: true,
parametersResolution: 'schema'
}, (err, conversionResult) => {

reqBody = conversionResult.output[0].data.item[0].item[0].request.body;
formData = reqBody.formdata[0];

expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);
expect(formData.type).to.equal('file');
done();
});
});
});
Loading