Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-to-postmanv2

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-to-postmanv2 - npm Package Compare versions

Comparing version 0.0.10 to 0.0.12

.npmignore

46

bin/openapi2postmanv2.js

@@ -70,30 +70,10 @@ #!/usr/bin/env node

if (testFlag) {
swaggerInput = fs.readFileSync('../examples/sampleswagger.yaml', 'utf8');
/**
* Helper function for the CLI to convert swagger data input
* @param {String} swaggerData - swagger data used for conversion input
* @returns {void}
*/
function convert(swaggerData) {
Converter.convert({
type: 'string',
data: swaggerInput
}, (err, status) => {
if (!status.result) {
console.log(status.reason); // eslint-disable-line no-console
}
else if (outputFile) {
let file = path.resolve(outputFile);
writetoFile(prettyPrintFlag, file, status.output[0].data);
}
else {
console.log(status.collection); // eslint-disable-line no-console
process.exit(0);
}
});
}
else if (inputFile) {
inputFile = path.resolve(inputFile);
console.log('Input file: ', inputFile); // eslint-disable-line no-console
// The last commit removed __dirname while reading inputFile
// this will fix https://github.com/postmanlabs/openapi-to-postman/issues/4
// inputFile should be read from the cwd, not the path of the executable
swaggerData = fs.readFileSync(inputFile, 'utf8');
Converter.convert({
type: 'string',
data: swaggerData

@@ -119,2 +99,16 @@ }, {}, (err, status) => {

}
if (testFlag) {
swaggerData = fs.readFileSync('../examples/sample-swagger.yaml', 'utf8');
convert(swaggerData);
}
else if (inputFile) {
inputFile = path.resolve(inputFile);
console.log('Input file: ', inputFile); // eslint-disable-line no-console
// The last commit removed __dirname while reading inputFile
// this will fix https://github.com/postmanlabs/openapi-to-postman/issues/4
// inputFile should be read from the cwd, not the path of the executable
swaggerData = fs.readFileSync(inputFile, 'utf8');
convert(swaggerData);
}
else {

@@ -121,0 +115,0 @@ program.emit('--help');

# OpenAPI-Postman Changelog
#### v0.0.12 (Apr 17, 2019)
* Fix for https://github.com/postmanlabs/openapi-to-postman/issues/36 - Property names with a . in the name are supported during schema faking
#### v0.0.11 (Apr 17, 2019)
* Fix for https://github.com/postmanlabs/openapi-to-postman/issues/47 - Accepting application/vnd.api+json headers as JSON
* Removing unused dependencies
* Fix CLI test commands (courtesy https://github.com/aerotog)
* Fix README typos (courtesy https://github.com/T1l3 and https://github.com/evertharmeling)
#### v0.0.10 (Jan 31, 2019)

@@ -4,0 +13,0 @@ * Safe property access to empty content/authHelper objects

@@ -24,2 +24,27 @@ const openApiErr = require('./error.js'),

/**
* @param {*} rootObject - the object from which you're trying to read a property
* @param {*} pathArray - each element in this array a property of the previous object
* @param {*} defValue - what to return if the required path is not found
* @returns {*} - required property value
* @description - this is similar to _.get(rootObject, pathArray.join('.')), but also works for cases where
* there's a . in the property name
*/
_getEscaped: function (rootObject, pathArray, defValue) {
if (!(pathArray instanceof Array)) {
return null;
}
if (!rootObject) {
return defValue;
}
if (_.isEmpty(pathArray)) {
return rootObject;
}
return this._getEscaped(rootObject[pathArray.shift()], pathArray, defValue);
},
/**
* Resolves references to components for a given schema.

@@ -56,4 +81,5 @@ * @param {*} schema (openapi) to resolve references.

// will be resolved - we don't care about anything after the components part
// splitRef.slice(2).join('.') will return 'schemas.PaginationEnvelope.properties.page'
resolvedSchema = _.get(components, splitRef.slice(2).join('.'));
// splitRef.slice(2) will return ['schemas', 'PaginationEnvelope', 'properties', 'page']
// not using _.get here because that fails if there's a . in the property name (Pagination.Envelope, for example)
resolvedSchema = this._getEscaped(components, splitRef.slice(2));
if (resolvedSchema) {

@@ -60,0 +86,0 @@ return this.resolveRefs(resolvedSchema, components, stack);

@@ -15,2 +15,3 @@ const sdk = require('postman-collection'),

APP_JSON = 'application/json',
APP_VND_JSON = 'application/vnd.api+json',
APP_JS = 'application/javascript',

@@ -576,3 +577,3 @@ APP_XML = 'application/xml',

_.each([APP_JSON, APP_XML], (supportedCType) => {
_.each([APP_JSON, APP_XML, APP_VND_JSON], (supportedCType) => {
// these are the content-types that we'd prefer to generate a body for

@@ -604,5 +605,9 @@ // in this order

responseBody = this.convertToPmBodyData(contentObj[cTypeHeader], cTypeHeader, this.options.indentCharacter);
if (cTypeHeader === APP_JSON) {
if (cTypeHeader === APP_JSON || cTypeHeader === APP_VND_JSON) {
responseBody = JSON.stringify(responseBody, null, this.options.indentCharacter);
}
else if (typeof responseBody !== 'string') {
// since the collection v2 schema only supports body being a string
responseBody = '';
}
return {

@@ -609,0 +614,0 @@ contentTypeHeader: cTypeHeader,

{
"name": "openapi-to-postmanv2",
"version": "0.0.10",
"version": "0.0.12",
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",

@@ -102,11 +102,6 @@ "com_postman_plugin": {

"dependencies": {
"async": "2.6.0",
"commander": "2.3.0",
"console-emoji": "0.0.2",
"js-yaml": "3.10.0",
"jsonschema": "1.2.2",
"lodash": "4.17.5",
"package.json": "2.0.1",
"path": "0.12.7",
"postman-collection": "3.3.0"
"js-yaml": "3.13.1",
"lodash": "4.17.11",
"postman-collection": "3.4.7"
},

@@ -116,3 +111,4 @@ "author": "Postman",

"devDependencies": {
"eslint": "5.4.0",
"chai": "4.1.2",
"eslint": "^5.16.0",
"eslint-plugin-jsdoc": "3.8.0",

@@ -123,4 +119,3 @@ "eslint-plugin-mocha": "5.2.0",

"istanbul": "0.4.5",
"mocha": "5.2.0",
"chai": "4.1.2"
"mocha": "5.2.0"
},

@@ -127,0 +122,0 @@ "scripts": {

@@ -195,3 +195,3 @@

| collectionName | info.title | - | |
| descrition | info.description + info.contact | - | |
| description | info.description + info.contact | - | |
| collectionVariables| server.variables + pathVariables | - | |

@@ -204,4 +204,4 @@ | folderName | paths.path | - | |

| request.url.raw | server.url (path level server >> openapi server) + path | - | |
| requser.url.variables | parameter (`in = path`) | - | [link](#Header/Path-param-conversion-example) |
| request.url.variables | parameter (`in = path`) | - | [link](#Header/Path-param-conversion-example) |
| request.url.params | parameter (`in = query`) | - | {"key": param.name, "value": [link](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-examples)}|
| api_key in (query or header) | components.securitySchemes.api_key | - ||

@@ -9,2 +9,5 @@ var expect = require('chai').expect,

},
schemaWithDotInKey = {
$ref: '#/components/schemas/schema.four'
},
components = {

@@ -32,11 +35,73 @@ schemas: {

}
},
'schema.four': {
type: 'object',
required: [
'id'
],
properties: {
id: {
type: 'integer',
format: 'int64'
}
}
}
}
},
output = deref.resolveRefs(schema, components);
output = deref.resolveRefs(schema, components),
output_withdot = deref.resolveRefs(schemaWithDotInKey, components);
expect(output).to.deep.include({ type: 'object',
required: ['id'],
properties: { id: { default: '<long>', type: 'integer' } } });
expect(output_withdot).to.deep.include({ type: 'object',
required: ['id'],
properties: { id: { default: '<long>', type: 'integer' } } });
done();
});
describe('_getEscaped should', function() {
var rootObject = {
person: {
name: {
firstName: 'John'
},
'key.with.period': true,
pets: ['Cooper', 'Calvin']
},
alive: true
};
it('work correctly for all _.get cases', function() {
// return object at path
expect(deref._getEscaped(rootObject, ['person', 'name'], 'Jane').firstName).to.equal('John');
// return object at path
expect(deref._getEscaped(rootObject, ['alive'], 'Jane')).to.equal(true);
// return primitive at path
expect(deref._getEscaped(rootObject, ['person', 'name', 'firstName'], 'Jane')).to.equal('John');
// return primitive at path with . in propname
expect(deref._getEscaped(rootObject, ['person', 'key.with.period'], 'Jane')).to.equal(true);
// return default for wrong path
expect(deref._getEscaped(rootObject, ['person', 'wrongname'], 'Jane')).to.equal('Jane');
// return array elem 0
expect(deref._getEscaped(rootObject, ['person', 'pets', 0], 'Hello?')).to.equal('Cooper');
// return array elem 1
expect(deref._getEscaped(rootObject, ['person', 'pets', 1], 'Hello?')).to.equal('Calvin');
// return array elem 2 (nonexistent)
expect(deref._getEscaped(rootObject, ['person', 'pets', 2], 'Pet not found')).to.equal('Pet not found');
// bad inputs should not crash the process
expect(deref._getEscaped(rootObject, { randomObject: 1 })).to.equal(null);
expect(deref._getEscaped(2, { randomObject: 1 })).to.equal(null);
expect(deref._getEscaped(null, { randomObject: 1 })).to.equal(null);
});
});
});

@@ -1275,2 +1275,29 @@ var expect = require('chai').expect,

});
it('with Content-Type application/vnd.api+json', function() {
var contentObj = {
'application/vnd.api+json': {
'schema': {
'type': 'object',
'required': [
'id',
'name'
],
'properties': {
id: {
type: 'integer',
format: 'int64'
},
name: {
type: 'string'
}
}
}
}
},
pmResponseBody;
Utils.options.schemaFaker = true;
pmResponseBody = JSON.parse(Utils.convertToPmResponseBody(contentObj).responseBody);
expect(pmResponseBody.id).to.equal('<long>');
expect(pmResponseBody.name).to.equal('<string>');
});
it('with Content-Type application/json and specified indentCharacter', function() {

@@ -1357,2 +1384,28 @@ var contentObj = {

});
it('with Content-Type unsupported', function() {
var contentObj = {
'application/vnd.api+json+unsupported': {
'schema': {
'type': 'object',
'required': [
'id',
'name'
],
'properties': {
id: {
type: 'integer',
format: 'int64'
},
name: {
type: 'string'
}
}
}
}
},
pmResponseBody;
Utils.options.schemaFaker = true;
pmResponseBody = Utils.convertToPmResponseBody(contentObj).responseBody;
expect(pmResponseBody).to.equal('');
});
// things remaining application/xml, application/javascript

@@ -1359,0 +1412,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc