diff --git a/README.md b/README.md index d06b27e64..bc2744f13 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,10 @@ The converter can be used as a CLI tool as well. The following [command line opt - `-p`, `--pretty` Used to pretty print the collection object while writing to a file -- `-h`, `--help` +- `-c`, `--config` + Used to supply options to the converter + +- `-h`, `--help` Specifies all the options along with a few usage examples on the terminal @@ -204,3 +207,22 @@ $ openapi2postmanv2 --test | request.url.variables | parameter (`in = path`) | - | [link](#Header/Path-param-conversion-example) | | request.url.params | parameter (`in = query`) | - | {"key": param.name, "value": [link](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-examples)}| | api_key in (query or header) | components.securitySchemes.api_key | - || + + +## CLI Configuration options + +These options are supported using the config file. + +| name | id | type | default/0 | availableOptions/0 | availableOptions/1 | description | external | usage/0 | +|----------------------------------------------------------|------------------------------|---------|-----------|--------------------|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------| +| Naming requests | requestNameSource | enum | Fallback | URL | Fallback | 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`. | true | CONVERSION | +| Set indent character | indentCharacter | enum | Space | Space | Tab | Option for setting indentation character | true | CONVERSION | +| Collapse redundant folders | collapseFolders | boolean | true | | | Importing will collapse all folders that have only one child element and lack persistent folder-level data. | true | CONVERSION | +| Request parameter generation | requestParametersResolution | enum | Schema | Example | Schema | 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. | true | CONVERSION | +| Response parameter generation | exampleParametersResolution | enum | Example | Example | Schema | 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. | true | CONVERSION | +| Folder organization | folderStrategy | enum | Paths | Paths | Tags | Select whether to create folders according to the spec’s paths or tags. | true | CONVERSION | +| Enable Schema Faking | schemaFaker | boolean | true | | | Whether or not schemas should be faked. | false | CONVERSION | +| Short error messages during request <> schema validation | shortValidationErrors | boolean | false | | | Whether detailed error messages are required for request <> schema validation operations. | true | VALIDATION | +| Properties to ignore during validation | validationPropertiesToIgnore | array | | | | 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 | true | VALIDATION | +| Whether MISSING_IN_SCHEMA mismatches should be returned | showMissingInSchemaErrors | boolean | false | | | MISSING_IN_SCHEMA indicates that an extra parameter was included in the request. For most use cases, this need not be considered an error. | true | VALIDATION | +| Show detailed body validation messages | detailedBlobValidation | boolean | false | | | Determines whether to show detailed mismatch information for application/json content in the request/response body. | true | VALIDATION | diff --git a/bin/openapi2postmanv2.js b/bin/openapi2postmanv2.js index 11025d98a..363c70b87 100755 --- a/bin/openapi2postmanv2.js +++ b/bin/openapi2postmanv2.js @@ -6,6 +6,7 @@ var program = require('commander'), inputFile, outputFile, prettyPrintFlag, + configFile, testFlag, swaggerInput, swaggerData; @@ -15,7 +16,8 @@ program .option('-s, --spec ', 'Convert given OPENAPI 3.0.0 spec to Postman Collection v2.0') .option('-o, --output ', 'Write the collection to an output file') .option('-t, --test', 'Test the OPENAPI converter') - .option('-p, --pretty', 'Pretty print the JSON file'); + .option('-p, --pretty', 'Pretty print the JSON file') + .option('-c, --config ', 'JSON file containing Converter options'); program.on('--help', function() { @@ -41,6 +43,7 @@ inputFile = program.spec; outputFile = program.output || false; testFlag = program.test || false; prettyPrintFlag = program.pretty || false; +configFile = program.config || false; swaggerInput; swaggerData; @@ -73,10 +76,17 @@ function writetoFile(prettyPrintFlag, file, collection) { * @returns {void} */ function convert(swaggerData) { + let options = {}; + if (configFile) { + configFile = path.resolve(configFile); + console.log('Config file: ', configFile); + options = JSON.parse(fs.readFileSync(configFile, 'utf8')); + } + Converter.convert({ type: 'string', data: swaggerData - }, {}, (err, status) => { + }, options, (err, status) => { if (err) { return console.error(err); } diff --git a/examples/config.json b/examples/config.json new file mode 100644 index 000000000..20023072e --- /dev/null +++ b/examples/config.json @@ -0,0 +1,13 @@ +{ + "requestNameSource": "Fallback", + "indentCharacter": "Space", + "collapseFolders": true, + "requestParametersResolution": "Schema", + "exampleParametersResolution": "Example", + "folderStrategy": "Paths", + "schemaFaker": true, + "shortValidationErrors": false, + "validationPropertiesToIgnore": [], + "showMissingInSchemaErrors": true, + "detailedBlobValidation": false +}