postman-to-openapi
postman-to-openapi copied to clipboard
feat: add default value from description
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
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
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.
@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