Skip to content

Conversation

@davidjgonzalez
Copy link

…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}}'
                    }
                }
            })

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

Successfully merging this pull request may close these issues.

1 participant