postman-code-generators icon indicating copy to clipboard operation
postman-code-generators copied to clipboard

[PowerShell] Simplify generated code by using here-strings

Open Josverl opened this issue 5 years ago • 4 comments

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}"

Josverl avatar Aug 18 '20 20:08 Josverl

@umeshp7 That means that there would be no use of sanitize function, right?

karmanya007 avatar Oct 24 '20 13:10 karmanya007

@umeshp7 PR opened. Please review.

karmanya007 avatar Oct 24 '20 14:10 karmanya007

@umeshp7 I think the travis tests need to be updated.

travisError

karmanya007 avatar Oct 24 '20 15:10 karmanya007

@karmanya007 This is the unit test inside Powershell. You might have to update that.

umeshp7 avatar Oct 25 '20 15:10 umeshp7

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.

dhwaneetbhatt avatar Mar 16 '23 06:03 dhwaneetbhatt

Thanks, has been a long wait, but thanks for following through.

Josverl avatar Apr 05 '23 07:04 Josverl