Socket
Socket
Sign inDemoInstall

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.15 to 0.0.16

test/data/valid_openapi/wrong-body.yaml

2

bin/openapi2postmanv2.js

@@ -14,3 +14,3 @@ #!/usr/bin/env node

program
.version('0.0.1')
.version(require('../package.json').version, '-v, --version')
.option('-s, --spec <spec>', 'Convert given OPENAPI 3.0.0 spec to Postman Collection v2.0')

@@ -17,0 +17,0 @@ .option('-o, --output <output>', 'Write the collection to an output file')

# OpenAPI-Postman Changelog
#### v0.0.16 (July 22, 2019)
* Corrected code snippet in README (courtesy https://github.com/simonlampen)
* Fix for https://github.com/postmanlabs/openapi-to-postman/issues/44 - Prevent crashes for specs that contain a root endpoint (courtesy https://github.com/pitpit)
* Ignoring missing body propertes in schema objects
#### v0.0.14 / v0.0.15 (June 5, 2019)

@@ -4,0 +9,0 @@ * Added system tests, updated lockfiles for npm@6.4.1

@@ -18,3 +18,3 @@ /**

this.requests = options ? options.requests : []; // request will be an array of objects
this.requests = []; // request will always be an array of objects

@@ -21,0 +21,0 @@ this.addChildren = function (child, value) {

@@ -283,3 +283,4 @@ const sdk = require('postman-collection'),

var methods = [];
pathKeys.forEach(function(element) {
// TODO: Show warning for incorrect schema if !pathKeys
pathKeys && pathKeys.forEach(function(element) {
if (METHODS.includes(element)) {

@@ -302,3 +303,4 @@ methods.push(element);

// split the path into indiv. segments for trie generation
currentPath = path.split('/').filter((pathItem) => {
// unless path it the root endpoint
currentPath = path === '' ? ['(root)'] : path.split('/').filter((pathItem) => {
// remove any empty pathItems that might have cropped in

@@ -308,2 +310,3 @@ // due to trailing or double '/' characters

});
pathLength = currentPath.length;

@@ -327,4 +330,2 @@

requestCount: 0,
requests: [],
children: {},
type: 'item-group'

@@ -1019,3 +1020,4 @@ }));

params = this.convertParamsWithStyle(encoding[key], value);
params.forEach((element) => {
// TODO: Show warning for incorrect schema if !params
params && params.forEach((element) => {
if (typeof element.value === 'object') { element.value = JSON.stringify(element.value); }

@@ -1395,3 +1397,4 @@ // element.value = JSON.stringify(element.value);

// extra form headers if encoding is present in request Body.
pmBody.formHeaders.forEach((element) => {
// TODO: Show warning for incorrect schema if !pmBody.formHeaders
pmBody.formHeaders && pmBody.formHeaders.forEach((element) => {
item.request.addHeader(element);

@@ -1398,0 +1401,0 @@ });

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

@@ -5,0 +5,0 @@ "homepage": "https://github.com/postmanlabs/openapi-to-postman",

@@ -110,5 +110,5 @@

Converter = require('openapi-to-postmanv2'),
openapiData = fs.readFileSync('sample-spec.yaml');
openapiData = fs.readFileSync('sample-spec.yaml', {encoding: 'UTF8'});
Converter.convert({ type: 'string', data: specPath },
Converter.convert({ type: 'string', data: openapiData },
{}, (err, conversionResult) => {

@@ -115,0 +115,0 @@ if (!conversionResult.result) {

@@ -1,1 +0,1 @@

{"item":[{"id":"2e79cac8-9528-45fd-9576-2942485f3dd6","name":"pets","item":[{"id":"b82067c6-3294-495a-b6a8-3f7c574fea7c","name":"List all pets","request":{"name":"List all pets","description":{},"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"description":"random variable","key":"variable","value":"<string>,<string>"},{"description":"another random variable","key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"key":"limit","value":"<integer>","description":"How many items to return at one time (max 100)"}],"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"837152fc-b084-44a8-92cc-978783090620","name":"An paged array of pets","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"key":"variable","value":"<string>,<string>"},{"key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"description":{"content":"How many items to return at one time (max 100)","type":"text/plain"},"key":"limit","value":"<integer>"}],"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"x-next","value":"<string>","description":"A link to the next page of responses"},{"key":"Content-Type","value":"application/json"}],"body":"[\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n },\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n }\n]","cookie":[],"_postman_previewlanguage":"json"},{"id":"a3f3d3e2-ad7f-42e2-b777-a7cc22669fbd","name":"unexpected error","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"key":"variable","value":"<string>,<string>"},{"key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"description":{"content":"How many items to return at one time (max 100)","type":"text/plain"},"key":"limit","value":"<integer>"}],"method":"GET","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]},{"id":"09736865-cf4d-4f97-a2f9-15ecbe9b2224","name":"Create a pet","request":{"name":"Create a pet","description":{},"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","auth":{"type":"noauth"}},"response":[{"id":"9b6a4e45-153a-4f27-90ab-c64dd434b2a9","name":"Null response","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","body":{}},"status":"Created","code":201,"header":[{"key":"Content-Type","value":"text/plain"}],"body":"","cookie":[],"_postman_previewlanguage":"text"},{"id":"90904388-7ddf-47ea-91b4-a873946c7b08","name":"unexpected error","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]},{"id":"c7180ee5-7ad7-4117-95f7-f99377b75779","name":"Info for a specific pet","request":{"name":"Info for a specific pet","description":{},"url":{"path":["pets",":petId"],"host":["{{baseUrl}}"],"query":[],"variable":[{"description":{"content":"The id of the pet to retrieve","type":"text/plain"},"type":"any","value":"<string>","key":"petId"}]},"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"6e12dce9-6659-4eaf-8da6-10d55d0a01ad","name":"Expected response to a valid request","originalRequest":{"url":{"path":["pets","<string>"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"Content-Type","value":"application/json"}],"body":"[\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n },\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n }\n]","cookie":[],"_postman_previewlanguage":"json"},{"id":"39ba69b7-9d8d-4765-bf8c-dfc147a26812","name":"unexpected error","originalRequest":{"url":{"path":["pets","<string>"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"GET","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]}],"event":[]}],"event":[],"variable":[{"id":"baseUrl","type":"string","value":"http://petstore.swagger.io/v1"}],"info":{"_postman_id":"7fa6d0b0-4ac5-445e-a05c-5d57aab4e4b4","name":"Swagger Petstore","version":{"raw":"1.0.0","major":1,"minor":0,"patch":0,"prerelease":[],"build":[],"string":"1.0.0"},"schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json","description":{"type":"text/plain"}}}
{"item":[{"id":"8220ae63-cb92-4113-9695-1343766639be","name":"pets","item":[{"id":"2cacfa36-68e2-4553-ac71-1d536b8e5361","name":"List all pets","request":{"name":"List all pets","description":{},"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"description":"random variable","key":"variable","value":"<string>,<string>"},{"description":"another random variable","key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"key":"limit","value":"<integer>","description":"How many items to return at one time (max 100)"}],"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"d9a844ca-0bb9-46db-b888-af0e640dafc3","name":"An paged array of pets","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"key":"variable","value":"<string>,<string>"},{"key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"description":{"content":"How many items to return at one time (max 100)","type":"text/plain"},"key":"limit","value":"<integer>"}],"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"x-next","value":"<string>","description":"A link to the next page of responses"},{"key":"Content-Type","value":"application/json"}],"body":"[\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n },\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n }\n]","cookie":[],"_postman_previewlanguage":"json"},{"id":"c3ec5152-7b76-488c-bcaf-ef15fb1c9542","name":"unexpected error","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[{"key":"variable","value":"<string>,<string>"},{"key":"variable2","value":"<long> <long>"}],"variable":[]},"header":[{"description":{"content":"How many items to return at one time (max 100)","type":"text/plain"},"key":"limit","value":"<integer>"}],"method":"GET","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]},{"id":"e64310bb-0596-4699-a312-2cc91db27218","name":"Create a pet","request":{"name":"Create a pet","description":{},"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","auth":{"type":"noauth"}},"response":[{"id":"97febb92-2532-41d4-8d40-4da972f5c4a5","name":"Null response","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","body":{}},"status":"Created","code":201,"header":[{"key":"Content-Type","value":"text/plain"}],"body":"","cookie":[],"_postman_previewlanguage":"text"},{"id":"a109f276-1dd5-43e9-b07c-7d41acaff26c","name":"unexpected error","originalRequest":{"url":{"path":["pets"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"POST","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]},{"id":"719593e6-cb6d-498c-84f9-02bf17ef8896","name":"Info for a specific pet","request":{"name":"Info for a specific pet","description":{},"url":{"path":["pets",":petId"],"host":["{{baseUrl}}"],"query":[],"variable":[{"description":{"content":"The id of the pet to retrieve","type":"text/plain"},"type":"any","value":"<string>","key":"petId"}]},"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"b6435887-3163-4530-8432-b9895644accc","name":"Expected response to a valid request","originalRequest":{"url":{"path":["pets","<string>"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"Content-Type","value":"application/json"}],"body":"[\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n },\n {\n \"id\": \"<long>\",\n \"name\": \"<string>\",\n \"tag\": \"<string>\"\n }\n]","cookie":[],"_postman_previewlanguage":"json"},{"id":"88994bbe-a260-4d11-ac5c-2d2905add27e","name":"unexpected error","originalRequest":{"url":{"path":["pets","<string>"],"host":["{{baseUrl}}"],"query":[],"variable":[]},"method":"GET","body":{}},"status":"Internal Server Error","code":500,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"code\": \"<integer>\",\n \"message\": \"<string>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]}],"event":[]}],"event":[],"variable":[{"id":"baseUrl","type":"string","value":"http://petstore.swagger.io/v1"}],"info":{"_postman_id":"8a2e2207-d88c-4b52-9da2-3439c8259ea5","name":"Swagger Petstore","version":{"raw":"1.0.0","major":1,"minor":0,"patch":0,"prerelease":[],"build":[],"string":"1.0.0"},"schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json","description":{"type":"text/plain"}}}

@@ -27,5 +27,6 @@ /**

let collection = conversionResult.output[0].data;
// eslint-disable-next-line no-console
// console.log(JSON.stringify(collection, null, 2));
fs.writeFileSync('./temp/temp-collection.json', JSON.stringify(collection, null, 2));
fs.writeFileSync(
path.join(__dirname, '../data/.temp/temp-collection.json'),
JSON.stringify(collection, null, 2)
);
done();

@@ -32,0 +33,0 @@ });

@@ -336,2 +336,42 @@ var expect = require('chai').expect,

});
// https://github.com/postmanlabs/openapi-to-postman/issues/80
it('should generate trie taking swagger specs with root endpoint declaration as input.', function (done) {
var openapi = {
'openapi': '3.0.0',
'info': {
'version': '1.0.0',
'title': 'Swagger Petstore',
'license': {
'name': 'MIT'
}
},
'servers': [
{
'url': 'http://petstore.swagger.io/{v1}'
}
],
'paths': {
'/': {
'get': {
'summary': 'List all pets',
'operationId': 'listPets',
'responses': {
'200': {
'description': 'An paged array of pets'
}
}
}
}
}
},
output = Utils.generateTrieFromPaths(openapi),
root = output.tree.root;
expect(root.children).to.be.an('object').that.has.all.keys('(root)');
expect(root.children['(root)'].requestCount).to.equal(1);
expect(root.children['(root)'].requests.length).to.equal(1);
done();
});
});

@@ -338,0 +378,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