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

Release/1.1.13 #205

Merged
merged 36 commits into from
Apr 21, 2020
Merged
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
59ccea4
Avoid storing in schema resolution cache if schema not resolved previ…
umeshp7 Mar 18, 2020
b767986
Merge branch 'develop' into feature/fix-schema-res-cache
umeshp7 Mar 27, 2020
471b87f
Fix failing tests
umeshp7 Mar 31, 2020
2203813
Add handling for escaped characters in deref.resolveRefs
umeshp7 Mar 31, 2020
2391764
Add unit test for path ref not found error
umeshp7 Apr 6, 2020
7b5caaa
Added support for resolving refs for VALIDATION with default being fo…
VShingala Apr 7, 2020
8aa67e5
Added tests for confirming change
VShingala Apr 7, 2020
8da0adf
Fixed URIError for invalid Uri in transaction
VShingala Apr 7, 2020
1afad53
Merge pull request #197 from postmanlabs/feature/fix-uri-error
abhijitkane Apr 8, 2020
7cf4217
Addressed comments regarding renaming RESOLVE_REFS_FOR to PROCESSING_…
VShingala Apr 8, 2020
1585a1e
Add handling for correct baseUrl formation
umeshp7 Apr 13, 2020
5072e87
Merge pull request #190 from postmanlabs/feature/resolve-ref-path
abhijitkane Apr 13, 2020
eb5cc8e
Merge pull request #196 from postmanlabs/feature/support-resolveref-f…
abhijitkane Apr 13, 2020
6e9a7af
Fixed invalid transaction paths and changed REQUEST_BODY to BODY for …
VShingala Apr 14, 2020
8bd37ae
Fixed typo
VShingala Apr 14, 2020
7ca547a
Added support for detaied validation errors with option detailedBlobV…
VShingala Apr 14, 2020
61d1b55
Updated getOptions structure tests for detailedValidationBlob option
VShingala Apr 14, 2020
6648f9d
Merge branch 'develop' into feature/fix-schema-res-cache
umeshp7 Apr 15, 2020
fecf172
Resolve refs for processing type VALIDATION upon request body validation
VShingala Apr 15, 2020
ce054e4
Added quotes ariund property names and use protactive lodash get
VShingala Apr 15, 2020
f2a56b4
Use bracket resolution for application/json
VShingala Apr 15, 2020
3a8a824
Use bracket resolution for application/json
VShingala Apr 15, 2020
28932e1
Add unit test for too many refs fix
umeshp7 Apr 15, 2020
7e67562
Merge pull request #198 from postmanlabs/feature/fixed-transactionpat…
abhijitkane Apr 15, 2020
f11caa5
Add safe check avoid undef error
umeshp7 Apr 16, 2020
bfc6d55
Merge branch 'develop' of github.com:postmanlabs/openapi-to-postman i…
VShingala Apr 17, 2020
5276a0d
Remove unnecessary handling for path level servers in convertRequestT…
umeshp7 Apr 17, 2020
7f7b7a1
Show detailed messages for request/response body only and Removed non…
VShingala Apr 17, 2020
39b76f6
Fixed getOptions test for detailedBlobValidation option
VShingala Apr 17, 2020
4b569de
Add special handling for local server urls
umeshp7 Apr 17, 2020
8718e7d
Merge pull request #188 from postmanlabs/feature/fix-schema-res-cache
umeshp7 Apr 17, 2020
1f2b518
Merge pull request #199 from postmanlabs/feature/show-body-mismatches
abhijitkane Apr 21, 2020
facbee8
Merge pull request #201 from postmanlabs/feature/server-url-bug-fix
abhijitkane Apr 21, 2020
aab6b77
Changelog for v1.1.13
umeshp7 Apr 21, 2020
a1b74ef
1.1.13
umeshp7 Apr 21, 2020
55c6586
Update changelog for v1.1.13
umeshp7 Apr 21, 2020
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
64 changes: 49 additions & 15 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
@@ -1529,7 +1529,7 @@ module.exports = {
return path.match(/(\{\{[^\/\{\}]+\}\})/g);
},

/** Separates outs collection and path variables from the reqUrl
/** Separates out collection and path variables from the reqUrl
*
* @param {string} reqUrl Request Url
* @param {Array} pathVars Path variables
@@ -1565,7 +1565,7 @@ module.exports = {
});
}

return { reqUrl, pathVars, collectionVars };
return { url: reqUrl, pathVars, collectionVars };
},

/**
@@ -1612,7 +1612,7 @@ module.exports = {
sanitizeResult = this.sanitizeUrlPathParams(reqUrl, reqParams.path);

// Updated reqUrl
reqUrl = sanitizeResult.reqUrl;
reqUrl = sanitizeResult.url;

// Updated reqParams.path
reqParams.path = sanitizeResult.pathVars;
@@ -1632,24 +1632,59 @@ module.exports = {

if (Array.isArray(localServers) && localServers.length) {
serverObj = operationItem.properties.servers[0];
baseUrl = serverObj.url.replace(/{/g, ':').replace(/}/g, '');
baseUrl += reqUrl;

// convert all {anything} to {{anything}}
baseUrl = this.fixPathVariablesInUrl(serverObj.url);

// add serverObj variables to pathVarArray
if (serverObj.variables) {
pathVarArray = this.convertPathVariables('method', [], serverObj.variables, components, options, schemaCache);
_.forOwn(serverObj.variables, (value, key) => {
pathVarArray.push({
name: key,
value: value.default || '',
description: this.getParameterDescription(value)
});
});

// use pathVarAray to sanitize url for path params and collection variables.
sanitizeResult = this.sanitizeUrlPathParams(baseUrl, pathVarArray);

// update the base url with update url
baseUrl = sanitizeResult.url;

// Add new collection variables to the variableStore
sanitizeResult.collectionVars.forEach((element) => {
if (!variableStore[element.name]) {
variableStore[element.name] = {
id: element.name,
value: element.value || '',
description: element.description,
type: 'collection'
};
}
});

// remove all the collection variables from serverObj.variables
serverObj.pathVariables = {};
sanitizeResult.pathVars.forEach((element) => {
serverObj.pathVariables[element.name] = serverObj.variables[element.name];
});

// use this new filterd serverObj.pathVariables
// to generate pm path variables.
pathVarArray = this.convertPathVariables('method', [],
serverObj.pathVariables, components, options, schemaCache);
}
baseUrl += reqUrl;
}
else {
// accounting for the overriding of the root level servers object if present at the path level
if (Array.isArray(globalServers) && globalServers.length) {
if (operationItem.servers[0].hasOwnProperty('variables')) {
serverObj = operationItem.servers[0];
baseUrl = serverObj.url.replace(/{/g, ':').replace(/}/g, '');
pathVariables = serverObj.variables;
}
else {
displayUrl = '{{' + operationItem.path + 'Url}}' + reqUrl;
}
// All the global servers present at the path level are taken care of in generateTrieFromPaths
// Just adding the same structure of the url as the display URL.
displayUrl = '{{' + operationItem.path + 'Url}}' + reqUrl;
}
// In case there are no server available use the baseUrl
else {
baseUrl += reqUrl;
if (pathVariables) {
@@ -2668,4 +2703,3 @@ module.exports = {
};
}
};

152 changes: 152 additions & 0 deletions test/data/valid_openapi/issue#160.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "#160",
"license": {
"name": "MIT"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/v1"
}
],
"paths": {
"/pets": {
"servers": [
{
"url": "http://petstore.swagger.io:{port}/{basePath}",
"variables": {
"port": {
"enum": [
"8443",
"443"
],
"default": "8443"
},
"basePath": {
"default": "v2"
}
}
}
],
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": [
"pets"
],
"parameters": [
{
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A paged array of pets",
"headers": {
"x-next": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
},
"post": {
"summary": "Create a pet",
"operationId": "createPets",
"tags": [
"pets"
],
"responses": {
"201": {
"description": "Null response"
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
}
14 changes: 13 additions & 1 deletion test/data/valid_openapi/server_overriding.json
Original file line number Diff line number Diff line change
@@ -22,7 +22,19 @@
"summary": "Should use the other domain",
"servers": [
{
"url": "https://other-api.example.com"
"url": "http://petstore.swagger.io:{port}/{basePath}",
"variables": {
"port": {
"enum": [
"8443",
"443"
],
"default": "8443"
},
"basePath": {
"default": "v2"
}
}
}
]
}
21 changes: 19 additions & 2 deletions test/unit/base.test.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
var testSpec = path.join(__dirname, VALID_OPENAPI_PATH + '/test.json'),
testSpec1 = path.join(__dirname, VALID_OPENAPI_PATH + '/test1.json'),
issue133 = path.join(__dirname, VALID_OPENAPI_PATH + '/issue#133.json'),
issue160 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#160.json'),
unique_items_schema = path.join(__dirname, VALID_OPENAPI_PATH + '/unique_items_schema.json'),
serverOverRidingSpec = path.join(__dirname, VALID_OPENAPI_PATH + '/server_overriding.json'),
infoHavingContactOnlySpec = path.join(__dirname, VALID_OPENAPI_PATH + '/info_having_contact_only.json'),
@@ -116,6 +117,21 @@ describe('CONVERT FUNCTION TESTS ', function() {
});
});

it('#GITHUB-160 should generate correct display url for path containing servers' +
issue160, function(done) {
var openapi = fs.readFileSync(issue160, 'utf8');
Converter.convert({ type: 'string', data: openapi }, {}, (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.item[0].item[0].request.url.host[0]).to.equal('{{petsUrl}}');
done();
});
});

it('Should not get stuck while resolving circular references' +
unique_items_schema, function(done) {
Converter.convert({ type: 'file', data:
@@ -200,12 +216,13 @@ describe('CONVERT FUNCTION TESTS ', function() {
let request = conversionResult.output[0].data.item[1].request,
protocol = request.url.protocol,
host = request.url.host.join('.'),
port = request.url.port,
path = request.url.path.join('/'),
endPoint = protocol + '://' + host + '/' + path,
endPoint = protocol + '://' + host + ':' + port + '/' + path,
host1 = conversionResult.output[0].data.variable[0].value,
path1 = conversionResult.output[0].data.item[0].request.url.path.join('/'),
endPoint1 = host1 + '/' + path1;
expect(endPoint).to.equal('https://other-api.example.com/secondary-domain/fails');
expect(endPoint).to.equal('http://petstore.swagger.io:{{port}}/:basePath/secondary-domain/fails');
expect(endPoint1).to.equal('https://api.example.com/primary-domain/works');
done();
});
4 changes: 2 additions & 2 deletions test/unit/util.test.js
Original file line number Diff line number Diff line change
@@ -2070,8 +2070,8 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
resultObj = SchemaUtils.sanitizeUrlPathParams('/anotherpath/{{path}}/{{new-path-variable}}.{{onemore}}',
pathParams);

expect(resultObj).to.have.property('reqUrl');
expect(resultObj.reqUrl).to.equal('/anotherpath/:path/{{new-path-variable}}.{{onemore}}');
expect(resultObj).to.have.property('url');
expect(resultObj.url).to.equal('/anotherpath/:path/{{new-path-variable}}.{{onemore}}');
expect(resultObj).to.have.property('pathVars');
expect(resultObj).to.have.property('collectionVars');