openapi-to-postmanv2
Advanced tools
Comparing version 0.0.10 to 0.0.12
@@ -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 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3695413
4
56
71508
+ Addedjs-yaml@3.13.1(transitive)
+ Addedmarked@0.6.2(transitive)
+ Addedmime-db@1.38.0(transitive)
+ Addedmime-types@2.1.22(transitive)
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedpostman-collection@3.4.7(transitive)
+ Addedpostman-url-encoder@1.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsanitize-html@1.20.0(transitive)
+ Addedsemver@6.0.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
- Removedasync@2.6.0
- Removedconsole-emoji@0.0.2
- Removedjsonschema@1.2.2
- Removedpackage.json@2.0.1
- Removedpath@0.12.7
- Removedabs@1.3.14(transitive)
- Removedasync@2.6.0(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedcolors@1.1.2(transitive)
- Removedconsole-emoji@0.0.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddeffy@2.2.4(transitive)
- Removedduplexer2@0.1.4(transitive)
- Removederr@1.1.1(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedexec-limiter@3.2.13(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.name@1.0.13(transitive)
- Removedgit-package-json@1.4.10(transitive)
- Removedgit-source@1.1.10(transitive)
- Removedgit-up@1.2.1(transitive)
- Removedgit-url-parse@5.0.1(transitive)
- Removedgot@5.7.1(transitive)
- Removedgry@5.0.8(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedinherits@2.0.3(transitive)
- Removedini@1.3.8(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-ssh@1.4.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removediterate-object@1.3.4(transitive)
- Removedjs-yaml@3.10.0(transitive)
- Removedjsonschema@1.2.2(transitive)
- Removedlimit-it@3.2.10(transitive)
- Removedlodash@4.17.5(transitive)
- Removedlowercase-keys@1.0.1(transitive)
- Removedmarked@0.5.0(transitive)
- Removedmime-db@1.36.0(transitive)
- Removedmime-types@2.1.20(transitive)
- Removedminimist@1.2.8(transitive)
- Removednode-emoji@1.4.1(transitive)
- Removednode-status-codes@1.0.0(transitive)
- Removednoop6@1.0.9(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedoargv@3.4.10(transitive)
- Removedobj-def@1.0.9(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedone-by-one@3.2.8(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedpackage-json@2.4.0(transitive)
- Removedpackage-json-path@1.0.9(transitive)
- Removedpackage.json@2.0.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedparse-url@1.3.11(transitive)
- Removedpath@0.12.7(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpostcss@6.0.23(transitive)
- Removedpostman-collection@3.3.0(transitive)
- Removedpostman-url-encoder@1.0.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedprocess@0.11.10(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedprotocols@1.4.82.0.1(transitive)
- Removedr-json@1.3.0(transitive)
- Removedr-package-json@1.0.9(transitive)
- Removedrc@1.2.8(transitive)
- Removedread-all-stream@3.1.0(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedregistry-auth-token@3.4.0(transitive)
- Removedregistry-url@3.1.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsanitize-html@1.19.0(transitive)
- Removedsemver@5.5.15.7.2(transitive)
- Removedsliced@1.0.1(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstring.prototype.codepointat@0.2.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtimed-out@3.1.3(transitive)
- Removedtmp@0.0.28(transitive)
- Removedtyppy@2.3.13(transitive)
- Removedul@5.2.15(transitive)
- Removedunzip-response@1.0.2(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
- Removedutil@0.10.4(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedw-json@1.3.10(transitive)
Updatedjs-yaml@3.13.1
Updatedlodash@4.17.11
Updatedpostman-collection@3.4.7