mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge branch 'develop' into bugfix/remove-folderStrategy-option
This commit is contained in:
124
lib/options.js
124
lib/options.js
@@ -12,64 +12,80 @@ module.exports = {
|
||||
* availableOptions - allowed values (only for type=enum)
|
||||
* description - human-readable description of the item
|
||||
* external - whether the option is settable via the API
|
||||
* usage - array of supported types of usage (i.e. CONVERSION, VALIDATION)
|
||||
*
|
||||
* @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
|
||||
* @param {Object} criteria Decribes required criteria for options to be returned. can have properties
|
||||
* external: <boolean>
|
||||
* usage: <array> (Array of supported usage type - CONVERSION, VALIDATION)
|
||||
* @returns {mixed} An array or object (depending on mode) that describes available options
|
||||
*/
|
||||
getOptions: function(mode = 'document') {
|
||||
getOptions: function(mode = 'document', criteria = {}) {
|
||||
// Override mode & criteria if first arg is criteria (objects)
|
||||
if (typeof mode === 'object') {
|
||||
criteria = mode;
|
||||
mode = 'document';
|
||||
}
|
||||
|
||||
let optsArray = [
|
||||
{
|
||||
name: 'Set request name source',
|
||||
name: 'Naming requests',
|
||||
id: 'requestNameSource',
|
||||
type: 'enum',
|
||||
default: 'fallback',
|
||||
availableOptions: ['url', 'fallback'],
|
||||
description: 'Option for setting source for a request name',
|
||||
external: true
|
||||
default: 'Fallback',
|
||||
availableOptions: ['Url', 'Fallback'],
|
||||
description: 'Determines how the requests inside the generated collection will be named.' +
|
||||
' If “Fallback” is selected, the request will be named after one of the following schema' +
|
||||
' values: `description`, `operationid`, `url`.',
|
||||
external: true,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Set indent character',
|
||||
id: 'indentCharacter',
|
||||
type: 'enum',
|
||||
default: ' ',
|
||||
availableOptions: [' ', '\t'],
|
||||
default: 'Space',
|
||||
availableOptions: ['Space', 'Tab'],
|
||||
description: 'Option for setting indentation character',
|
||||
external: true
|
||||
external: true,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Toggle for collapsing folder for long routes',
|
||||
name: 'Collapse redundant folders',
|
||||
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
|
||||
description: 'Importing will collapse all folders that have only one child element and lack ' +
|
||||
'persistent folder-level data.',
|
||||
external: true,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Set root request parameters type',
|
||||
name: 'Request parameter generation',
|
||||
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
|
||||
default: 'Schema',
|
||||
availableOptions: ['Example', 'Schema'],
|
||||
description: 'Select whether to generate the request parameters based on the' +
|
||||
' [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the' +
|
||||
' [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject)' +
|
||||
' in the schema.',
|
||||
external: true,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Set example request and response parameters type',
|
||||
name: 'Response parameter generation',
|
||||
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
|
||||
default: 'Example',
|
||||
availableOptions: ['Example', 'Schema'],
|
||||
description: 'Select whether to generate the response parameters based on the' +
|
||||
' [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the' +
|
||||
' [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject)' +
|
||||
' in the schema.',
|
||||
external: true,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Enable Schema Faking',
|
||||
@@ -77,15 +93,17 @@ module.exports = {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether or not schemas should be faked.',
|
||||
external: false
|
||||
external: false,
|
||||
usage: ['CONVERSION']
|
||||
},
|
||||
{
|
||||
name: 'Short error messages during request <> schema validation',
|
||||
id: 'shortValidationErrors',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether detailed error messages are required for request <> schema validation operations',
|
||||
external: false
|
||||
description: 'Whether detailed error messages are required for request <> schema validation operations.',
|
||||
external: true,
|
||||
usage: ['VALIDATION']
|
||||
},
|
||||
{
|
||||
name: 'Properties to ignore during validation',
|
||||
@@ -95,7 +113,8 @@ module.exports = {
|
||||
description: 'Specific properties (parts of a request/response pair) to ignore during validation.' +
|
||||
' Must be sent as an array of strings. Valid inputs in the array: PATHVARIABLE, QUERYPARAM,' +
|
||||
' HEADER, BODY, RESPONSE_HEADER, RESPONSE_BODY',
|
||||
external: true
|
||||
external: true,
|
||||
usage: ['VALIDATION']
|
||||
},
|
||||
{
|
||||
name: 'Whether MISSING_IN_SCHEMA mismatches should be returned',
|
||||
@@ -104,15 +123,48 @@ module.exports = {
|
||||
default: false,
|
||||
description: 'MISSING_IN_SCHEMA indicates that an extra parameter was included in the request. For most ' +
|
||||
'use cases, this need not be considered an error.',
|
||||
external: true
|
||||
external: true,
|
||||
usage: ['VALIDATION']
|
||||
},
|
||||
{
|
||||
name: 'Show detailed body validation messages',
|
||||
id: 'detailedBlobValidation',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Determines whether to show detailed mismatch information for application/json content ' +
|
||||
'in the request/response body.',
|
||||
external: true,
|
||||
usage: ['VALIDATION']
|
||||
}
|
||||
];
|
||||
|
||||
// Filter options based on criteria
|
||||
if (_.isObject(criteria)) {
|
||||
typeof criteria.external === 'boolean' && (optsArray = _.filter(optsArray, { external: criteria.external }));
|
||||
if (_.isArray(criteria.usage)) {
|
||||
let tempOptsArray = [];
|
||||
|
||||
_.forEach(criteria.usage, (usageCriteria) => {
|
||||
tempOptsArray = _.concat(tempOptsArray, _.filter(optsArray, (option) => {
|
||||
return _.includes(option.usage, usageCriteria);
|
||||
}));
|
||||
});
|
||||
optsArray = tempOptsArray;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode === 'use') {
|
||||
// options to be used as default kv-pairs
|
||||
let defOptions = {};
|
||||
_.each(optsArray, (opt) => {
|
||||
defOptions[opt.id] = opt.default;
|
||||
// special handling for indent character as in documentation it states `Tab` and `Space`
|
||||
// but for the generation mode, we need actual values
|
||||
if (opt.id === 'indentCharacter') {
|
||||
defOptions[opt.id] = opt.default === 'tab' ? '\t' : ' ';
|
||||
}
|
||||
else {
|
||||
defOptions[opt.id] = opt.default;
|
||||
}
|
||||
});
|
||||
return defOptions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user