postmanlabs / swagger2-to-postman

Converter for swagger 2.0 JSON to Postman Collection
Apache License 2.0
120 stars 56 forks source link

#46 - Support transforming swagger variable names to specified Postma… #47

Open davidjgonzalez opened 5 years ago

davidjgonzalez commented 5 years ago

…n variables.

This adds a new 'transforms' key to the options object in the format:

this.options = {
   transforms: {
        header: {
            '<SWAGGER HEADER NAME>': '<POSTMAN REPLACEMENT>',
       }, path: {
            '<SWAGGER PATH VARIABLE NAME>': '<POSTMAN REPLACEMENT>',
      }, formData: {
            '<SWAGGER FORMDATA VARIABLE NAME>': '<POSTMAN REPLACEMENT>',
      }, body: {
            '<SWAGGER BODY VARIABLE NAME>': '<POSTMAN REPLACEMENT>',
      }
   }
}

The <POSTMAN REPLACEMENT> must contain the wrapping double-curly braces ({{...}}). The <POSTMAN REPLACEMENT> may contain any other hardcoded text/values as well. For instance, a common need for this is setting an Authorization HTTP header, that requires a Bearer prefix, for example:

this.options = {
   transforms: {
        header: {
           'Authorization': 'Bearer {{ACCESS_TOKEN}}'
        }
   }
}

An example initializing the Swagger2Postman converter w/ transform parameters is as follows:

 converter = new Swagger2Postman({
                transforms: {
                    header: {
                        'api-key': '{{API_KEY}}',
                        'Authorization': 'Bearer {{ACCESS_TOKEN}}',
                    },
                    path: {
                        'ownerId': '{{OWNER_ID}}'
                    }
                }
            })