mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
New SchemaPack API exposed, validatorAgainstHistory v1
This commit is contained in:
109
lib/options.js
Normal file
109
lib/options.js
Normal file
@@ -0,0 +1,109 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
// default options
|
||||
// if mode=document, returns an array of name/id/default etc.
|
||||
|
||||
/**
|
||||
* name - human-readable name for the option
|
||||
* id - key to pass the option with
|
||||
* type - boolean or enum for now
|
||||
* default - the value that's assumed if not specified
|
||||
* availableOptions - allowed values (only for type=enum)
|
||||
* description - human-readable description of the item
|
||||
* external - whether the option is settable via the API
|
||||
*
|
||||
* @param {string} [mode='document'] Describes use-case. 'document' will return an array
|
||||
* with all options being described. 'use' will return the default values of all options
|
||||
* @returns {mixed} An array or object (depending on mode) that describes available options
|
||||
*/
|
||||
getOptions: function(mode = 'document') {
|
||||
let optsArray = [
|
||||
{
|
||||
name: 'Set request name source',
|
||||
id: 'requestNameSource',
|
||||
type: 'enum',
|
||||
default: 'fallback',
|
||||
availableOptions: ['url', 'fallback'],
|
||||
description: 'Option for setting source for a request name',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Set indent character',
|
||||
id: 'indentCharacter',
|
||||
type: 'enum',
|
||||
default: ' ',
|
||||
availableOptions: [' ', '\t'],
|
||||
description: 'Option for setting indentation character',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Toggle for collapsing folder for long routes',
|
||||
id: 'collapseFolders',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Determines whether the importer should attempt to collapse redundant folders into one.' +
|
||||
'Folders are redundant if they have only one child element, and don\'t' +
|
||||
'have any folder-level data to persist.',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Set root request parameters type',
|
||||
id: 'requestParametersResolution',
|
||||
type: 'enum',
|
||||
default: 'schema',
|
||||
availableOptions: ['example', 'schema'],
|
||||
description: 'Determines how request parameters (query parameters, path parameters, headers,' +
|
||||
'or the request body) should be generated. Setting this to schema will cause the importer to' +
|
||||
'use the parameter\'s schema as an indicator; `example` will cause the example (if provided)' +
|
||||
'to be picked up.',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Set example request and response parameters type',
|
||||
id: 'exampleParametersResolution',
|
||||
type: 'enum',
|
||||
default: 'example',
|
||||
availableOptions: ['example', 'schema'],
|
||||
description: 'Determines how response parameters (query parameters, path parameters, headers,' +
|
||||
'or the request body) should be generated. Setting this to schema will cause the importer to' +
|
||||
'use the parameter\'s schema as an indicator; `example` will cause the example (if provided)' +
|
||||
'to be picked up.',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Set folder strategy',
|
||||
id: 'folderStrategy',
|
||||
type: 'enum',
|
||||
default: 'paths',
|
||||
availableOptions: ['paths', 'tags'],
|
||||
description: 'Determines whether the importer should attempt to create the folders according' +
|
||||
'to paths or tags which are given in the spec.',
|
||||
external: true
|
||||
},
|
||||
{
|
||||
name: 'Enable Schema Faking',
|
||||
id: 'schemaFaker',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether or not schemas should be faked.',
|
||||
external: false
|
||||
}
|
||||
];
|
||||
|
||||
if (mode === 'use') {
|
||||
// options to be used as default kv-pairs
|
||||
let defOptions = {};
|
||||
_.each(optsArray, (opt) => {
|
||||
defOptions[opt.id] = opt.default;
|
||||
});
|
||||
return defOptions;
|
||||
}
|
||||
|
||||
// options to be used as documentation
|
||||
return _.filter(optsArray, (opt) => {
|
||||
// only return options that are externally controllable
|
||||
return opt.external === true;
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user