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 YAML as template format #43

Open
natenho opened this issue Oct 6, 2019 · 2 comments
Open

Consider YAML as template format #43

natenho opened this issue Oct 6, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@natenho
Copy link
Owner

natenho commented Oct 6, 2019

Is your feature request related to a problem? Please describe.
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}"
  },
  "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
  }
}

Describe the solution you'd like
YAML 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 YAML:

---
request:
  method: PUT
  route: customers/{id}
  
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

There is a C# implementation: YamlDotNet

Describe alternatives you've considered
To use mustache or handlebars templating alternatives would require a DSL to be created. This alternative is not suitable for Mockaco as its proposal is to reduce the learning curve, keeping C# as the scripting language.

Additional context
There are some disadvantages using YAML:

  • It's not so easy to find a YAML formatter (this one is good)
  • You can't use tabs to indent the file (😔)
  • YAML syntax has more nuances than JSON
  • There is no C# project implementing YAML 1.2 spec
@natenho natenho added the enhancement New feature or request label Oct 9, 2019
@tkrafael
Copy link

I think we should stick to Razor for templating as it is almost native to aspnet core.

@natenho
Copy link
Owner Author

natenho commented Oct 31, 2019

Hey, it's actually a nice idea! I'll take a closer look on this possiblity as it would be better aligned with Mockaco's proposal instead of YAML format, which I've been resistant to embrace, to be honest. I would appreciate if you could provide more details, maybe some kind of template examples of how your approach would look like.
Thanks!!

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

2 participants