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

No support for multi-line MUSTACHE templates in initializerJson.json #1840

Open
Arc-E-Tect opened this issue Feb 8, 2024 · 0 comments
Open

Comments

@Arc-E-Tect
Copy link

Describe the issue
I am using the initializerJson.json to initialize Mock-Server. For my team it is more convenient to manage a standard set of mock-responses this way.

When specifying literal request/responses we can use definitions that are easy to format and read, but when using templates this is cumbersome and the documentation is not very helpful.

What you are trying to do
Trying to define a MUSTACHE based template in initializerJson.json file as

[{
    "httpRequest": {
        "method": "GET",
        "path": "/persons/{id}",
        "pathParameters": {
            "id": [
                "[0-9\\-]+"
            ]
        }
    },
    "httpResponseTemplate": {
        "templateType": "MUSTACHE",
        "template": {
            "statusCode": 200,
            "headers": {
                "Content-Type": [
                    "application/json"
                ]
            },
            "body": {
                "name": "John",
                "id": "{{path.id}}"
            }
        }
    }
}]

but I have to specify it as:

[{
    "httpRequest": {
      "method": "GET",        
      "path": "/persons/{id}",
      "pathParameters": {
            "id": ["[0-9\\-]+"]
        }
    },
    "httpResponseTemplate": {
        "templateType": "MUSTACHE",
        "template": "{\"statusCode\":200,\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":{\"name\":\"John\",\"id\":\"{{path.id}}\"}}"
    }
}]

Note that the template field is one long hard to maintain string.

Something tells me that there must be a way for a more convenient way to specify this.

MockServer version
5.15

To Reproduce
Use the snippets above as initializerJson,json file and the first snippet will result in an error

  1. How you are running MockServer (i.e maven plugin, docker, etc): Docker
  2. Code you used to create expectations: initializerJson.json
  3. What error you saw: exception while loading JSON initialization file with file watcher, ignoring file

Expected behaviour
What you expected to happen: support for friendly format of json when using templates

MockServer Log
Log output, as INFO level (or lower)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant