Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 |
14 changes: 12 additions & 2 deletions bin/openapi2postmanv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var program = require('commander'),
inputFile,
outputFile,
prettyPrintFlag,
configFile,
testFlag,
swaggerInput,
swaggerData;
Expand All @@ -15,7 +16,8 @@ program
.option('-s, --spec <spec>', 'Convert given OPENAPI 3.0.0 spec to Postman Collection v2.0')
.option('-o, --output <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 <config>', 'JSON file containing Converter options');


program.on('--help', function() {
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions examples/config.json
Original file line number Diff line number Diff line change
@@ -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
}