Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider json5 as template format #149

Open
2 tasks done
evorios opened this issue Dec 11, 2024 · 0 comments
Open
2 tasks done

Consider json5 as template format #149

evorios opened this issue Dec 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@evorios
Copy link

evorios commented Dec 11, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure a similar issue has not already been created

Description

To use the scripting engine on mock templates, most of times there is a need to write an invalid JSON structure, like this:

{
  "request": {
    "method": "PUT",
    "route": "customers/{id}"
    "condition": "<#=
      var isAuthCorrect = Request.Header["Authorization"]?.ToString() == "Basic bG9naW46cGFzc3dvcmQ=";
      return isAuthCorrect;
    #>"
  },
  "response": {
    "status": "OK",
    "body": {
      "url": "<#= Request.Url?.ToString() #>",
      "customerId": "<#= Request.Route["id"]?.ToString() #>",
      "acceptHeader": "<#= Request.Header["Content-Type"]?.ToString() #>",
      "queryString": "<#= Request.Query["dummy"]?.ToString() #>",
      "requestBodyAttribute": "<#= Request.Body["address"]?[0]?.ToString() #>"
    },
    "indented": false
  }
}

Proposed solution

json5 seems to be suitable alternative to write templates with C# scripts, as it is more permissive on content, like the example bellow, which is a completely valid json5:

{
  request: {
    method: 'PUT',
    route: 'customers/{id}',
    condition: '<#=\
      var isAuthCorrect = Request.Header["Authorization"]?.ToString() == "Basic bG9naW46cGFzc3dvcmQ=";\
      return isAuthCorrect;\
    #>'
  },
  response: {
    status: 'OK',
    body: {
      url: '<#= Request.Url?.ToString() #>',
      customerId: '<#= Request.Route["id"]?.ToString() #>',
      acceptHeader: '<#= Request.Header["Content-Type"]?.ToString() #>',
      queryString: '<#= Request.Query["dummy"]?.ToString() #>',
      requestBodyAttribute: '<#= Request.Body["address"]?[0]?.ToString() #>'
    },
    indented: false
  }
}

Alternatives

nop

Additional context

There are some disadvantages using json5:

  • no fully supported by vscode;
  • need to append c#-strings by symbol '\' for multiline code.
@evorios evorios added the enhancement New feature or request label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant