mockserver icon indicating copy to clipboard operation
mockserver copied to clipboard

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

Open Arc-E-Tect opened this issue 1 year ago • 0 comments

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)

Arc-E-Tect avatar Feb 08 '24 23:02 Arc-E-Tect