mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
added options for schemaFaker & reqName
This commit is contained in:
6
index.js
6
index.js
@@ -7,17 +7,17 @@ module.exports = {
|
|||||||
convert: function(input, options, cb) {
|
convert: function(input, options, cb) {
|
||||||
try {
|
try {
|
||||||
if (input.type === 'string') {
|
if (input.type === 'string') {
|
||||||
return convert(input.data, cb);
|
return convert(input.data, options, cb);
|
||||||
}
|
}
|
||||||
else if (input.type === 'json') {
|
else if (input.type === 'json') {
|
||||||
return convert(input.data, cb);
|
return convert(input.data, options, cb);
|
||||||
}
|
}
|
||||||
else if (input.type === 'file') {
|
else if (input.type === 'file') {
|
||||||
return fs.read(input.data, function(err, data) {
|
return fs.read(input.data, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
return convert(data, cb);
|
return convert(data, options, cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return cb(null, {
|
return cb(null, {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var sdk = require('postman-collection'),
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
convert: function (data, callback) {
|
convert: function (data, options, callback) {
|
||||||
var validation = util.parseSpec(data),
|
var validation = util.parseSpec(data),
|
||||||
openapi = {},
|
openapi = {},
|
||||||
description,
|
description,
|
||||||
@@ -30,6 +30,9 @@ var sdk = require('postman-collection'),
|
|||||||
if (!validation.result) {
|
if (!validation.result) {
|
||||||
callback(validation);
|
callback(validation);
|
||||||
}
|
}
|
||||||
|
// options
|
||||||
|
util.options.requestName = options.hasOwnProperty('requestName') ? options.requestName : 'operationId';
|
||||||
|
util.options.schemaFaker = options.hasOwnProperty('schemaFaker') ? options.schemaFaker : true;
|
||||||
|
|
||||||
// TODO - Have to handle global level security scheme
|
// TODO - Have to handle global level security scheme
|
||||||
|
|
||||||
@@ -109,6 +112,6 @@ var sdk = require('postman-collection'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
// module.exports = converter;
|
// module.exports = converter;
|
||||||
module.exports = function(json, callback) {
|
module.exports = function(json, options, callback) {
|
||||||
converter.convert(json, callback);
|
converter.convert(json, options, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
16
lib/util.js
16
lib/util.js
@@ -95,6 +95,7 @@ class Trie {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
// list of predefined schemas in components
|
// list of predefined schemas in components
|
||||||
components: {},
|
components: {},
|
||||||
|
options: {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the neccessary server variables to the collection
|
* Adds the neccessary server variables to the collection
|
||||||
@@ -196,9 +197,11 @@ module.exports = {
|
|||||||
i,
|
i,
|
||||||
summary,
|
summary,
|
||||||
path,
|
path,
|
||||||
|
xthis,
|
||||||
// creating a root node for the trie (serves as the root dir)
|
// creating a root node for the trie (serves as the root dir)
|
||||||
trie = new Trie(root);
|
trie = new Trie(root);
|
||||||
|
|
||||||
|
xthis = this;
|
||||||
for (path in paths) {
|
for (path in paths) {
|
||||||
if (paths.hasOwnProperty(path)) {
|
if (paths.hasOwnProperty(path)) {
|
||||||
// decalring a variable to be in this loops context only
|
// decalring a variable to be in this loops context only
|
||||||
@@ -256,7 +259,7 @@ module.exports = {
|
|||||||
|
|
||||||
currentNode.addMethod({
|
currentNode.addMethod({
|
||||||
name: summary,
|
name: summary,
|
||||||
id: operationItem.operationId,
|
id: operationItem[xthis.options.requestName],
|
||||||
method: method,
|
method: method,
|
||||||
path: path,
|
path: path,
|
||||||
properties: operationItem,
|
properties: operationItem,
|
||||||
@@ -297,7 +300,7 @@ module.exports = {
|
|||||||
_.forEach(pathVariables, (variable) => {
|
_.forEach(pathVariables, (variable) => {
|
||||||
variables.push({
|
variables.push({
|
||||||
key: variable.name,
|
key: variable.name,
|
||||||
value: safeSchemaFaker(variable.schema || {}, this.components),
|
value: this.options.schemaFaker ? safeSchemaFaker(variable.schema || {}, this.components) : '',
|
||||||
description: variable.description || ''
|
description: variable.description || ''
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -408,7 +411,7 @@ module.exports = {
|
|||||||
_.forOwn(responseHeaders, (value, key) => {
|
_.forOwn(responseHeaders, (value, key) => {
|
||||||
header = {
|
header = {
|
||||||
key: key,
|
key: key,
|
||||||
value: safeSchemaFaker(value.schema || {}, this.components),
|
value: this.options.schemaFaker ? safeSchemaFaker(value.schema || {}, this.components) : '',
|
||||||
description: value.description || ''
|
description: value.description || ''
|
||||||
};
|
};
|
||||||
headerArray.push(header);
|
headerArray.push(header);
|
||||||
@@ -484,7 +487,7 @@ module.exports = {
|
|||||||
// This part is to remove format:binary from any string-type properties
|
// This part is to remove format:binary from any string-type properties
|
||||||
// will cause schemaFaker to crash if left untreated
|
// will cause schemaFaker to crash if left untreated
|
||||||
if (bodyObj.hasOwnProperty('schema')) {
|
if (bodyObj.hasOwnProperty('schema')) {
|
||||||
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components);
|
bodyData = this.options.schemaFaker ? safeSchemaFaker(bodyObj.schema || {}, this.components) : '';
|
||||||
}
|
}
|
||||||
else if (bodyObj.hasOwnProperty('examples')) {
|
else if (bodyObj.hasOwnProperty('examples')) {
|
||||||
bodyData = this.getExampleData(openapi, bodyObj.examples);
|
bodyData = this.getExampleData(openapi, bodyObj.examples);
|
||||||
@@ -522,7 +525,8 @@ module.exports = {
|
|||||||
_.forEach(queryParameters, (param) => {
|
_.forEach(queryParameters, (param) => {
|
||||||
// check for existence of schema
|
// check for existence of schema
|
||||||
if (param.hasOwnProperty('schema')) {
|
if (param.hasOwnProperty('schema')) {
|
||||||
paramValue = safeSchemaFaker(param.schema, this.components); // fake data generated
|
// fake data generated
|
||||||
|
paramValue = this.options.schemaFaker ? safeSchemaFaker(param.schema, this.components) : '';
|
||||||
paramType = param.schema.type;
|
paramType = param.schema.type;
|
||||||
// checking the type of the query parameter
|
// checking the type of the query parameter
|
||||||
if (paramType === 'array') {
|
if (paramType === 'array') {
|
||||||
@@ -607,7 +611,7 @@ module.exports = {
|
|||||||
|
|
||||||
_.forEach(headers, (header) => {
|
_.forEach(headers, (header) => {
|
||||||
if (header.hasOwnProperty('schema')) {
|
if (header.hasOwnProperty('schema')) {
|
||||||
fakeData = safeSchemaFaker(header.schema || {}, this.components);
|
fakeData = options.schemaFaker ? safeSchemaFaker(header.schema || {}, this.components) : '';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fakeData = '';
|
fakeData = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user