postman-code-generators
postman-code-generators copied to clipboard
[PowerShell] Simplify generated code by using here-strings
The current implementation of the PowerShell generator requires a lot of escapes ``" for each quote and linefeed
this makes the generated core hard to read and change and verify.
Describe the solution you'd like
get rid of the escapes by using a PowerShell here-strings @" .... "@
I would preferer the double-quoted version as that will support variable replacement.
Proposed use of here-string:
$body = @"
{
"type":"message",
"attachments":[
{
"contentType":"application/vnd.microsoft.card.adaptive",
"contentUrl":null,
"content":
// insert card here
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Publish Adaptive Card schema",
"weight": "bolder",
"size": "medium"
}
]
//up to here
}
]
}
"@
Current use of many escapes:
$body = "{
`n `"type`":`"message`",
`n `"attachments`":[
`n {
`n `"contentType`":`"application/vnd.microsoft.card.adaptive`",
`n `"contentUrl`":null,
`n `"content`":
`n// insert card here
`n{
`n `"$schema`": `"http://adaptivecards.io/schemas/adaptive-card.json`",
`n `"type`": `"AdaptiveCard`",
`n `"version`": `"1.0`",
`n `"body`": [
`n {
`n `"type`": `"TextBlock`",
`n `"text`": `"Publish Adaptive Card schema`",
`n `"weight`": `"bolder`",
`n `"size`": `"medium`"
`n }
`n]
`n
`n//up to here
`n
`n }
`n ]
`n}"
@umeshp7 That means that there would be no use of sanitize function, right?
@umeshp7 PR opened. Please review.
@umeshp7 I think the travis tests need to be updated.

@karmanya007 This is the unit test inside Powershell. You might have to update that.
This is fixed in the latest version v10.12. Closing this issue. Fixed as part of https://github.com/postmanlabs/postman-code-generators/pull/679.
Thanks, has been a long wait, but thanks for following through.