mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge pull request #103 from Dhroov7/bugfix/showing_undefined_on_optional_info_fields
Handle OAS specs with missing properties in the info object
This commit is contained in:
@@ -102,10 +102,22 @@ var sdk = require('postman-collection'),
|
|||||||
|
|
||||||
// ---- Collection Description ----
|
// ---- Collection Description ----
|
||||||
// Adding the collection description and using any relevant contact info
|
// Adding the collection description and using any relevant contact info
|
||||||
description = _.get(openapi, 'info.description');
|
description = _.get(openapi, 'info.description', '');
|
||||||
if (_.get(openapi, 'info.contact')) {
|
if (_.get(openapi, 'info.contact')) {
|
||||||
contact = 'Name : ' + openapi.info.contact.name + '\n\nEmail : ' + openapi.info.contact.email + '\n';
|
contact = [];
|
||||||
description += '\n\nContact Support: \n{\n\n' + contact + '\n}';
|
if (openapi.info.contact.name) {
|
||||||
|
contact.push(' Name: ' + openapi.info.contact.name);
|
||||||
|
}
|
||||||
|
if (openapi.info.contact.email) {
|
||||||
|
contact.push(' Email: ' + openapi.info.contact.email);
|
||||||
|
}
|
||||||
|
if (contact.length > 0) {
|
||||||
|
// why to add unnecessary lines if there is no description
|
||||||
|
if (description !== '') {
|
||||||
|
description += '\n\n';
|
||||||
|
}
|
||||||
|
description += 'Contact Support:\n' + contact.join('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.generatedStore.collection.describe(description);
|
this.generatedStore.collection.describe(description);
|
||||||
|
|
||||||
|
|||||||
29
test/data/valid_openapi/info_having_contact_only.json
Normal file
29
test/data/valid_openapi/info_having_contact_only.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "Swagger Petstore",
|
||||||
|
"contact": {
|
||||||
|
"name": "API Support",
|
||||||
|
"url": "http://www.example.com/support",
|
||||||
|
"email": "support@example.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "http://petstore.swagger.io/v1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/pets": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Info for a specific pet",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Expected response to a valid request"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
test/data/valid_openapi/info_having_description_only.json
Normal file
25
test/data/valid_openapi/info_having_description_only.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "Swagger Petstore",
|
||||||
|
"description": "Hey, this is the description."
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "http://petstore.swagger.io/v1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/pets": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Info for a specific pet",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Expected response to a valid request"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,11 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
var pathPrefix = VALID_OPENAPI_PATH + '/test.json',
|
var pathPrefix = VALID_OPENAPI_PATH + '/test.json',
|
||||||
specPath = path.join(__dirname, pathPrefix),
|
specPath = path.join(__dirname, pathPrefix),
|
||||||
pathPrefix1 = VALID_OPENAPI_PATH + '/test1.json',
|
pathPrefix1 = VALID_OPENAPI_PATH + '/test1.json',
|
||||||
specPath1 = path.join(__dirname, pathPrefix1);
|
specPath1 = path.join(__dirname, pathPrefix1),
|
||||||
|
pathPrefix2 = VALID_OPENAPI_PATH + '/info_having_contact_only.json',
|
||||||
|
specPath2 = path.join(__dirname, pathPrefix2),
|
||||||
|
pathPrefix3 = VALID_OPENAPI_PATH + '/info_having_description_only.json',
|
||||||
|
specPath3 = path.join(__dirname, pathPrefix3);
|
||||||
|
|
||||||
it('Should generate collection conforming to schema for and fail if not valid ' +
|
it('Should generate collection conforming to schema for and fail if not valid ' +
|
||||||
specPath, function(done) {
|
specPath, function(done) {
|
||||||
@@ -37,6 +40,28 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
expect(conversionResult.output[0].data).to.have.property('info');
|
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('item');
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('[Github #102]- Should generate collection info with only contact info' +
|
||||||
|
specPath2, function(done) {
|
||||||
|
Converter.convert({ type: 'file', data: specPath2 }, { schemaFaker: true }, (err, conversionResult) => {
|
||||||
|
let description;
|
||||||
|
description = conversionResult.output[0].data.info.description;
|
||||||
|
expect(description.content).to
|
||||||
|
.equal('Contact Support:\n Name: API Support\n Email: support@example.com');
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('[Github #102]- Should generate collection info with only description' +
|
||||||
|
specPath3, function(done) {
|
||||||
|
Converter.convert({ type: 'file', data: specPath3 }, { schemaFaker: true }, (err, conversionResult) => {
|
||||||
|
let description;
|
||||||
|
description = conversionResult.output[0].data.info.description;
|
||||||
|
expect(description.content).to
|
||||||
|
.equal('Hey, this is the description.');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user