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

Fixed an issue where duplicate collection variables were generated for certain definitions. #796

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions lib/common/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ function getSpecVersion({ type, data, specificationVersion }) {
const openapi30 = getVersionRegexp(VERSION_30),
openapi31 = getVersionRegexp(VERSION_31),
openapi20 = getVersionRegexp(VERSION_20),
is30 = data.match(openapi30),
is31 = data.match(openapi31),
is20 = data.match(openapi20);
is30 = typeof data === 'string' && data.match(openapi30),
is31 = typeof data === 'string' && data.match(openapi31),
is20 = typeof data === 'string' && data.match(openapi20);

let version = DEFAULT_SPEC_VERSION;

if (is30) {
Expand Down
5 changes: 5 additions & 0 deletions libV2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ module.exports = {
}
});

// Remove duplicate variables as different requests could end up creating same variables
if (!_.isEmpty(collection.variable)) {
collection.variable = _.uniqBy(collection.variable, 'key');
}

return cb(null, {
result: true,
output: [{
Expand Down
56 changes: 56 additions & 0 deletions test/data/valid_openapi/duplicateCollectionVars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"openapi": "3.0.1",
"info": {
"title": "MyTitle",
"description": "My Description",
"version": "1.0.0",
"x-ms-generated-by": {
"toolName": "Microsoft.OpenApi.OData",
"toolVersion": "1.0.9.0"
}
},
"paths": {
"/Path1({MyParam})": {
"description": "My path1 description",
"get": {
"tags": [
"MyTag"
],
"summary": "does path1",
"operationId": "Path1",
"parameters": [
{
"name": "MyParam",
"in": "path",
"description": "My Param",
"schema": {
"type": "string",
"nullable": true
}
}
]
}
},
"/Path2({MyParam})": {
"description": "My path2 description",
"get": {
"tags": [
"MyTag"
],
"summary": "does path2",
"operationId": "Path2",
"parameters": [
{
"name": "MyParam",
"in": "path",
"description": "My Param",
"schema": {
"type": "string",
"nullable": true
}
}
]
}
}
}
}
22 changes: 21 additions & 1 deletion test/unit/convertV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
multiContentTypesMultiExample =
path.join(__dirname, VALID_OPENAPI_PATH, '/multiContentTypesMultiExample.json'),
multiExampleRequestVariousResponse =
path.join(__dirname, VALID_OPENAPI_PATH, '/multiExampleRequestVariousResponse.yaml');
path.join(__dirname, VALID_OPENAPI_PATH, '/multiExampleRequestVariousResponse.yaml'),
duplicateCollectionVars =
path.join(__dirname, VALID_OPENAPI_PATH, '/duplicateCollectionVars.json');


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

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

Check warning on line 311 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 311 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 311 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 @@ -318,7 +320,7 @@
done();
});
});
it.skip('Should collapse child and parent folder when parent has only one child' +

Check warning on line 323 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 323 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 323 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 @@ -332,7 +334,7 @@
done();
});
});
it.skip('Should generate collection without creating folders and having only one request' +

Check warning on line 337 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 337 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 337 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 @@ -2728,4 +2730,22 @@
});
});
});

it('[Github #11884] Should not contain duplicate variables created from requests path', function (done) {
const openapi = fs.readFileSync(duplicateCollectionVars, 'utf8');
Converter.convertV2({ type: 'string', data: openapi }, { parametersResolution: 'Example' },
(err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);
expect(conversionResult.output.length).to.equal(1);
expect(conversionResult.output[0].type).to.equal('collection');
expect(conversionResult.output[0].data).to.have.property('info');
expect(conversionResult.output[0].data).to.have.property('item');
expect(conversionResult.output[0].data).to.have.property('variable');
expect(conversionResult.output[0].data.variable).to.have.lengthOf(2);
expect(conversionResult.output[0].data.variable[0]).to.have.property('key', 'baseUrl');
expect(conversionResult.output[0].data.variable[1]).to.have.property('key', 'MyParam');
done();
});
});
});
Loading