mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
setting default values of options through getOptions function
This commit is contained in:
58
index.js
58
index.js
@@ -1,4 +1,4 @@
|
|||||||
var convert = require('./lib/convert.js'),
|
var converter = require('./lib/convert.js'),
|
||||||
validate = require('./lib/validate.js'),
|
validate = require('./lib/validate.js'),
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ module.exports = {
|
|||||||
if (input.type === 'string' || input.type === 'json') {
|
if (input.type === 'string' || input.type === 'json') {
|
||||||
// no need for extra processing before calling the converter
|
// no need for extra processing before calling the converter
|
||||||
// string can be JSON or YAML
|
// string can be JSON or YAML
|
||||||
return convert(input.data, options, cb);
|
return converter.convert(input.data, options, cb);
|
||||||
}
|
}
|
||||||
else if (input.type === 'file') {
|
else if (input.type === 'file') {
|
||||||
return fs.readFile(input.data, 'utf8', function(err, data) {
|
return fs.readFile(input.data, 'utf8', function(err, data) {
|
||||||
@@ -16,7 +16,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the file contents were JSON or YAML
|
// if the file contents were JSON or YAML
|
||||||
return convert(data, options, cb);
|
return converter.convert(data, options, cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return cb(null, {
|
return cb(null, {
|
||||||
@@ -52,56 +52,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getOptions: function() {
|
getOptions: function() {
|
||||||
return [
|
return converter.getOptions();
|
||||||
{
|
|
||||||
name: 'Toggle for faking schema',
|
|
||||||
id: 'schemaFaker',
|
|
||||||
type: 'boolean',
|
|
||||||
default: true,
|
|
||||||
description: 'Option for Fake the schema using json or xml schema faker'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Toggle for collapsing folder for long routes',
|
|
||||||
id: 'collapseLongFolders',
|
|
||||||
type: 'boolean',
|
|
||||||
default: true,
|
|
||||||
description: 'Collapse folders in case of long routes leading to unnecessary folders'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Set root request body type',
|
|
||||||
id: 'rootRequestBodyType',
|
|
||||||
type: 'string',
|
|
||||||
default: 'schema',
|
|
||||||
description: 'Option for setting root request body between schema or example'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Set example request and response body type',
|
|
||||||
id: 'exampleBodyType',
|
|
||||||
type: 'string',
|
|
||||||
default: 'example',
|
|
||||||
description: 'Option for setting example request and response body between schema or example'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Set folder strategy',
|
|
||||||
id: 'folderStrategy',
|
|
||||||
type: 'string',
|
|
||||||
default: 'paths',
|
|
||||||
description: 'Option for setting folder creating strategy between paths or tags'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Set indent character',
|
|
||||||
id: 'indentCharacter',
|
|
||||||
type: 'string',
|
|
||||||
default: ' ',
|
|
||||||
description: 'Option for setting indentation character'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Set request name source',
|
|
||||||
id: 'requestNameSource',
|
|
||||||
type: 'string',
|
|
||||||
default: 'fallback',
|
|
||||||
description: 'Option for setting source for a request name'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
107
lib/convert.js
107
lib/convert.js
@@ -47,6 +47,7 @@ var sdk = require('postman-collection'),
|
|||||||
convert: function (data, options, callback) {
|
convert: function (data, options, callback) {
|
||||||
var validation = util.parseSpec(data),
|
var validation = util.parseSpec(data),
|
||||||
openapi = {},
|
openapi = {},
|
||||||
|
definedOptions = converter.getOptions(),
|
||||||
description,
|
description,
|
||||||
contact;
|
contact;
|
||||||
|
|
||||||
@@ -57,12 +58,18 @@ var sdk = require('postman-collection'),
|
|||||||
|
|
||||||
// set default options
|
// set default options
|
||||||
util.options = {
|
util.options = {
|
||||||
requestNameSource: (options.hasOwnProperty('requestNameSource') ? options.requestNameSource : 'fallback'),
|
requestNameSource: (options.hasOwnProperty('requestNameSource') ? options.requestNameSource :
|
||||||
schemaFaker: (options.hasOwnProperty('schemaFaker') ? options.schemaFaker : true),
|
definedOptions[0].default),
|
||||||
indentCharacter: (options.hasOwnProperty('indentCharacter') ? options.indentCharacter : ' '),
|
schemaFaker: (options.hasOwnProperty('schemaFaker') ? options.schemaFaker :
|
||||||
collapseLongFolders: (options.hasOwnProperty('collapseLongFolders') ? options.collapseLongFolders : true),
|
definedOptions[1].default),
|
||||||
rootRequestBodyType: (options.hasOwnProperty('rootRequestBodyType') ? options.rootRequestBodyType : 'schema'),
|
indentCharacter: (options.hasOwnProperty('indentCharacter') ? options.indentCharacter :
|
||||||
exampleBodyType: (options.hasOwnProperty('exampleBodyType') ? options.exampleBodyType : 'example')
|
definedOptions[2].default),
|
||||||
|
collapseLongFolders: (options.hasOwnProperty('collapseLongFolders') ? options.collapseLongFolders :
|
||||||
|
definedOptions[3].default),
|
||||||
|
rootRequestBodyType: (options.hasOwnProperty('rootRequestBodyType') ? options.rootRequestBodyType :
|
||||||
|
definedOptions[4].default),
|
||||||
|
exampleBodyType: (options.hasOwnProperty('exampleBodyType') ? options.exampleBodyType :
|
||||||
|
definedOptions[5].default)
|
||||||
};
|
};
|
||||||
|
|
||||||
// @TODO - Have to handle global level security scheme
|
// @TODO - Have to handle global level security scheme
|
||||||
@@ -167,25 +174,81 @@ var sdk = require('postman-collection'),
|
|||||||
data: this.generatedStore.collection.toJSON()
|
data: this.generatedStore.collection.toJSON()
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getOptions: function() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: 'Set request name source',
|
||||||
|
id: 'requestNameSource',
|
||||||
|
type: 'string',
|
||||||
|
default: 'fallback',
|
||||||
|
description: 'Option for setting source for a request name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Toggle for faking schema',
|
||||||
|
id: 'schemaFaker',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description: 'Option for Fake the schema using json or xml schema faker'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Set indent character',
|
||||||
|
id: 'indentCharacter',
|
||||||
|
type: 'string',
|
||||||
|
default: ' ',
|
||||||
|
description: 'Option for setting indentation character'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Toggle for collapsing folder for long routes',
|
||||||
|
id: 'collapseLongFolders',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description: 'Collapse folders in case of long routes leading to unnecessary folders'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Set root request body type',
|
||||||
|
id: 'rootRequestBodyType',
|
||||||
|
type: 'string',
|
||||||
|
default: 'schema',
|
||||||
|
description: 'Option for setting root request body between schema or example'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Set example request and response body type',
|
||||||
|
id: 'exampleBodyType',
|
||||||
|
type: 'string',
|
||||||
|
default: 'example',
|
||||||
|
description: 'Option for setting example request and response body between schema or example'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Set folder strategy',
|
||||||
|
id: 'folderStrategy',
|
||||||
|
type: 'string',
|
||||||
|
default: 'paths',
|
||||||
|
description: 'Option for setting folder creating strategy between paths or tags'
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
module.exports = function(json, options, callback) {
|
convert: function(json, options, callback) {
|
||||||
try {
|
try {
|
||||||
converter.convert(json, options, callback);
|
converter.convert(json, options, callback);
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (e instanceof OpenApiErr) {
|
|
||||||
// Something wrong with the spec
|
|
||||||
callback(null, {
|
|
||||||
result: false,
|
|
||||||
reason: e.message
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// Unhandled exception, rethrow
|
if (e instanceof OpenApiErr) {
|
||||||
callback(e);
|
// Something wrong with the spec
|
||||||
|
callback(null, {
|
||||||
|
result: false,
|
||||||
|
reason: e.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Unhandled exception, rethrow
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
getOptions: converter.getOptions
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user