joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
605 stars 105 forks source link

feat: add default value from description #196

Closed EloB closed 2 years ago

EloB commented 2 years ago

This PR doesn't contain any tests for default value but I've tried it and seems to work.

https://github.com/joolfe/postman-to-openapi/issues/195

Here is a playground for the regexp [default=value] https://regex101.com/r/oGS42o/1

EloB commented 2 years ago

Another suggestion is to but it will become a breaking change. To strip description from schema when it's an empty string.

function extractDescription (description) {
  const value = (description || '').replace(/ ?(\[required\]|\[default=(.*?)(?<!\\)\]) ?/gi, '').trim()
  if (!value) return {}
  return { description: value }
}

https://github.com/EloB/postman-to-openapi/blob/351bee93f58eedc44af36712f0e04dc3493276cd/lib/index.js#L240-L243

joolfe commented 2 years ago

Hi @EloB,

Thanks for your contribution, please consider to add tests so the PR could be evaluated, if this is just an example code I will just close and take into consideration for the feature implementation thanks.

Best Regards.

EloB commented 2 years ago

@joolfe Sorry for late reply. I ended up using a different solution but if you like the proposal you can finalize this. :)

Thanks for your time <3