Added powershell here strings to powershell-restmethod codegen
Fixes #322 . Got rid of the escapes by using a PowerShell here-strings in powershell-restmethod codegen.
Request 1
method: 'POST',
header: [
{
key: 'Content-Type',
value: 'text/plain'
}
],
url:{
raw: 'https://mockbin.org/request',
protocol: 'https',
host: [
'mockbin',
'org'
],
path: [
'request'
]
},
body: {
'mode': 'raw',
'raw': 'Hello world'
},
description: 'Description'
Conversion
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "text/plain")
$body = @"Hello world"@
$response = Invoke-RestMethod 'https://mockbin.org/request' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Request 2
method: 'POST',
header: [],
body: {
mode: 'graphql',
graphql: {
query: '{ body { graphql } }',
variables: '{"variable_key": "variable_value"}'
}
},
url: {
raw: 'http://postman-echo.com/post',
protocol: 'http',
host: [
'postman-echo',
'com'
],
path: [
'post'
]
}
Conversion
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$body = @"{"query":"{ body { graphql } }","variables":{"variable_key":"variable_value"}}"@
$response = Invoke-RestMethod 'http://postman-echo.com/post' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
@umeshp7 All checks have passed and I have added the sample outputs.
@karmanya007 I have enabled newman tests for poweshell codegen. These tests run the generated snippet in powershell and compare the output with that generated by newman. You can see in the CI logs that some of the tests are failing due to incorrect escaping of characters in the string. We have to get those tests to pass before we can merge your changes.
@karmanya007 I have enabled newman tests for poweshell codegen. These tests run the generated snippet in powershell and compare the output with that generated by newman. You can see in the CI logs that some of the tests are failing due to incorrect escaping of characters in the string. We have to get those tests to pass before we can merge your changes.
@webholik On it!
@karmanya007 Any updates here? Looks like there are some conflicts.
@umeshp7 Had a marriage in my family so I was not active as much. I know the fix. Just have to implement it. Will do so shortly.
Getting these three errors. @Toronto00 , @umeshp7 Could you guide me in the correct direction on how to approach these conflicts.

@webholik Are the 1st and 3rd error from wrong newman tests, maybe?
@karmanya007 1st error is because you are not escaping $ character in the output string. If $ is present in a string then Powershell tries to replace it with a variable. In this case it is replacing it with the value of $test, which isn't defined, so it is just putting empty string here.
2nd error again is just wrong escaping. ` character must be properly escaped.
3rd has been fixed in #421. You should rebase your PR on top of it.
@karmanya007 We recently pushed changes to use here-strings in Powershell. Could you check if this PR would still be required?