joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
596 stars 104 forks source link

Support postman `:params` in api path & add global environments file with `-g` #133

Closed Chia-Yu-hung closed 3 years ago

Chia-Yu-hung commented 3 years ago
  1. Can use Path Variables :param in postman.

    • user can directly describe the variables in postman.
    • swagger can show variable description. Screen Shot 2021-07-31 at 11 54 39 PM
  2. Can replace {{variable}} with real value by use global environment json file.

    • user can export postman environments json, and use -g add this file, that can replace the {{variable}} to real value.
    • swagger can show example value. Screen Shot 2021-08-01 at 12 03 30 AM
Chia-Yu-hung commented 3 years ago

76 can be resolved

joolfe commented 3 years ago

Hi @Chia-Yu-hung,

First thanks so much for your support :-) but... Pull request shoul contain only one feature please and also test that cover the new code.

The #76 is work in progress and not only for path variables but for all variables in a postman collection, never mind the position, so please don't include this as part of the pull as is already being developed and is double effort, thanks!

Best regards

Chia-Yu-hung commented 3 years ago

Hi @joolfe,

Thanks for your reply, I will fix your comment and push again~

I will separate :params and -g to two branch, and also test that cover then.

Best regards

joolfe commented 3 years ago

Hi @Chia-Yu-hung,

About the -g option as I already mention this feature is not needed the #76 issue is work in progress and already cover this feature with an option parameter.

Best Regards.

Chia-Yu-hung commented 3 years ago

Hi @joolfe, About #134 how did I bring the global variable ? because I export the postman global environment json, format like below

        "name": "Local",
    "values": [
        {
            "key": "url",
            "value": "http://127.0.0.1:8888",
            "enabled": true
        },
        {
            "key": "project",
            "value": "default",
            "enabled": true
        }
        ]

mean I need replace values to additionalVars and set replaceVars true, so that I can replace the {{variable}} ?

btw, If I used this method to replace {{variable}} in all file, api path also will be replaced, this is expected?

Best Regards.

joolfe commented 3 years ago

Hi @Chia-Yu-hung,

Please have a look to the documentation about the new feature that replace vars, if you have additional questions I think a issue is better than a pull request for that discussion.

mean I need replace values to additionalVars and set replaceVars true, so that I can replace the {{variable}} ?

Variable replacement has a performance cost for this reason you need to explicitly activate this when process the postman collection using the option replaceVars: true, by default the library get the variables that are stored in the postman collection file in the field variable, this are the ones that Postman docs call collection variables but as there are many other scopes in postman as Global, Environment, Data, Local... there are an additional way to provide variable values for replacing the option additionalVars that is just a json object with key/value pairs.

btw, If I used this method to replace {{variable}} in all file, api path also will be replaced, this is expected?

To avoid some variable to be replace just don´t pass a key/value for this variable, I mean, if you don't want to replace a path variable {{user_id}} just don´t pass a variable with a value, this is a deliberate behaviour implemented to avoid this kind of use cases.

Best Regards.