Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigFile options are overwritten by CLI options #315

Closed
thim81 opened this issue Dec 18, 2020 · 5 comments
Closed

ConfigFile options are overwritten by CLI options #315

thim81 opened this issue Dec 18, 2020 · 5 comments

Comments

@thim81
Copy link
Contributor

thim81 commented Dec 18, 2020

The options from the ConfigFile are getting overwritten by the DefinedOptions, which should contain the CLI -O values but they contain all the CLI options and not the property

openapi2postmanv2 -s openapi.yaml -o postman.json -p -c postman/openapi-to-postman-config.json

openapi2postmanv2.js - Line 122

function convert(swaggerData) {
  let options = {};

  console.log('options', options)

// apply options from config file if present
  if (configFile) {
    configFile = path.resolve(configFile);
    console.log('Options Config file: ', configFile); // eslint-disable-line no-console
    options = JSON.parse(fs.readFileSync(configFile, 'utf8'));
  }

  console.log('options configFile', options)

  // override options provided via cli
  if (definedOptions) {
    options = definedOptions;
  }

  console.log('options configFile', options)

OUTPUT

options {}
Options Config file:  /Users/tim/Sites/DevPortal/api-smc/postman/openapi-to-postman-config.json
options configFile {
  requestNameSource: 'Fallback',
  indentCharacter: 'Space',
  collapseFolders: true,
  requestParametersResolution: 'Example',
  exampleParametersResolution: 'Example',
  folderStrategy: 'Tags',
  schemaFaker: true,
  includeAuthInfoInExample: true,
  shortValidationErrors: false,
  validationPropertiesToIgnore: [],
  showMissingInSchemaErrors: true,
  detailedBlobValidation: false
}
options definedOptions [
  Option {
    flags: '-v, --version',
    required: false,
    optional: false,
    bool: true,
    short: '-v',
    long: '--version',
    description: 'output the version number'
  },
  Option {
    flags: '-s, --spec <spec>',
    required: true,
    optional: false,
    bool: true,
    short: '-s',
    long: '--spec',
    description: 'Convert given OPENAPI 3.0.0 spec to Postman Collection v2.0'
  },
  Option {
    flags: '-o, --output <output>',
    required: true,
    optional: false,
    bool: true,
    short: '-o',
    long: '--output',
    description: 'Write the collection to an output file'
  },
  Option {
    flags: '-t, --test',
    required: false,
    optional: false,
    bool: true,
    short: '-t',
    long: '--test',
    description: 'Test the OPENAPI converter'
  },
  Option {
    flags: '-p, --pretty',
    required: false,
    optional: false,
    bool: true,
    short: '-p',
    long: '--pretty',
    description: 'Pretty print the JSON file'
  },
  Option {
    flags: '-c, --options-config <optionsConfig>',
    required: true,
    optional: false,
    bool: true,
    short: '-c',
    long: '--options-config',
    description: 'JSON file containing Converter options'
  },
  Option {
    flags: '-O, --options <options>',
    required: true,
    optional: false,
    bool: true,
    short: '-O',
    long: '--options',
    description: 'comma separated list of options'
  },
  Option {
    flags: '-g, --generate <generate>',
    required: true,
    optional: false,
    bool: true,
    short: '-g',
    long: '--generate',
    description: 'Generate postman tests given the JSON file with test options'
  }
]

If you use

openapi2postmanv2 -s openapi.yaml -o postman.json -p -c postman/openapi-to-postman-config.json -O folderStrategy=Tags

Then the OUTPUT is correct

options {}
Options Config file:  /Users/tim/Sites/DevPortal/api-smc/postman/openapi-to-postman-config.json
options configFile {
  requestNameSource: 'Fallback',
  indentCharacter: 'Space',
  collapseFolders: true,
  requestParametersResolution: 'Example',
  exampleParametersResolution: 'Example',
  folderStrategy: 'Tags',
  schemaFaker: true,
  includeAuthInfoInExample: true,
  shortValidationErrors: false,
  validationPropertiesToIgnore: [],
  showMissingInSchemaErrors: true,
  detailedBlobValidation: false
}
options definedOptions { folderStrategy: 'Tags' }
thim81 pushed a commit to thim81/openapi-to-postman that referenced this issue Dec 18, 2020
@thim81
Copy link
Contributor Author

thim81 commented Dec 18, 2020

Proposal to solve this:

openapi2postmanv2.js - Line 55

.option('-O, --options <options>', 'comma separated list of options', parseOptions)

Replace with

.option('-O, --options-cli <optionsCli>', 'comma separated list of options', parseOptions)

openapi2postmanv2.js Line 82

definedOptions = program.options || {};

Replace with

definedOptions = program.optionsCli || {};

thim81 pushed a commit to thim81/openapi-to-postman that referenced this issue Dec 18, 2020
thim81 pushed a commit to thim81/openapi-to-postman that referenced this issue Dec 18, 2020
@VShingala
Copy link
Member

Thanks for raising issue and PR as well 😄. I have reviewed the PR and it looks good to me apart from the change suggested. Let me know when you address the change. I will approve and merge the PR.

@thim81
Copy link
Contributor Author

thim81 commented Jan 22, 2021

@VShingala I'll look into the suggested change of correct if possible

@thim81
Copy link
Contributor Author

thim81 commented Jan 22, 2021

PR is updated and should be ready to go

VShingala added a commit that referenced this issue Jan 27, 2021
ConfigFile options are overwritten by CLI options #315
@thim81
Copy link
Contributor Author

thim81 commented Jan 28, 2021

Resolved as part of the 2.1.0 release

@thim81 thim81 closed this as completed Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants