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

Mustache template unable to access body.<field> #1911

Open
juber-nunes opened this issue Oct 2, 2024 · 0 comments
Open

Mustache template unable to access body.<field> #1911

juber-nunes opened this issue Oct 2, 2024 · 0 comments

Comments

@juber-nunes
Copy link

Describe the issue
Mustache template unable to access body.

What you are trying to do
Description of what you are trying to do so we can understand the context of the problem

MockServer version
5.15.0

To Reproduce
Steps to reproduce the issue:

  1. How you are running MockServer (i.e maven plugin, docker, etc)
  2. Code you used to create expectations

mockServerClient("localhost", 1081)
.mockAnyResponse({
"httpRequest": {
"method": "POST",
"path": "/mock-endpoint",
"headers": {
"Content-Type": ["application/json"]
},
"body": {
"type": "JSON",
}

  },
  "httpResponseTemplate": {
    "template": JSON.stringify({
        "statusCode": 200,
        "headers": {
            "Content-Type": ["application/json"]
        },
        "body": {
            "id": "{{ uuid }}",  
            "time": "{{ now_iso_8601 }}",   
            'message': "{{{jsonPath request.body '$.message'}}}",
            'to': '{{{ request.body.to }}}',
            'from': '1111111111111'
        },
        'delay': {
            'timeUnit': 'MILLISECONDS',
        }
  }),
    "templateType": "MUSTACHE",
    
  },
  1. What error you saw

Expected behaviour
To return field

MockServer Log
2024-10-02 17:03:32 5.15.0 INFO 1081 request:

{
"method" : "POST",
"path" : "/mock-endpoint",
"headers" : {
"user-agent" : [ "PostmanRuntime/7.42.0" ],
"postman-token" : [ "d858c7d9-d7b9-4ff0-bea9-255399791bcf" ],
"host" : [ "172.22.118.120:1081" ],
"content-type" : [ "application/json" ],
"content-length" : [ "152" ],
"connection" : [ "keep-alive" ],
"accept-encoding" : [ "gzip, deflate, br" ],
"accept" : [ "/" ]
},
"keepAlive" : true,
"secure" : false,
"protocol" : "HTTP_1_1",
"localAddress" : "127.0.0.1:1081",
"remoteAddress" : "127.0.0.1:37752",
"body" : {
"message" : "Your message content",
"to" : [ "+1234567890" ],
"from" : "+13473450776",
"media" : [ ],
"priority" : "default",
"tags" : { }
}
}

matched expectation:

{
"httpRequest" : {
"method" : "POST",
"path" : "/mock-endpoint",
"headers" : {
"Content-Type" : [ "application/json" ]
}
},
"httpResponseTemplate" : {
"template" : "{"statusCode":200,"headers":{"Content-Type":["application/json"]},"body":{"id":"{{ uuid }}","time":"{{ now_iso_8601 }}","message":"{{{jsonPath request.body '$.message'}}}","to":"{{{ request.body.to }}}","from":"1111111111111"},"delay":{"timeUnit":"MILLISECONDS"}}",
"templateType" : "MUSTACHE"
},
"id" : "788c5024-0027-426a-a36e-859a4691f073",
"priority" : 0,
"timeToLive" : {
"unlimited" : true
},
"times" : {
"unlimited" : true
}
}

2024-10-02 17:03:32 5.15.0 INFO 1081 generated output:

{"statusCode":200,"headers":{"Content-Type":["application/json"]},"body":{"id":"07348bcf-c348-4e22-adb2-f138cc348257","time":"2024-10-02T16:03:32.868205485Z","message":"","to":"","from":"1111111111111"},"delay":{"timeUnit":"MILLISECONDS"}}

from template:

{"statusCode":200,"headers":{"Content-Type":["application/json"]},"body":{"id":"{{ uuid }}","time":"{{ now_iso_8601 }}","message":"{{{jsonPath request.body '$.message'}}}","to":"{{{ request.body.to }}}","from":"1111111111111"},"delay":{"timeUnit":"MILLISECONDS"}}

for request:

{
"method" : "POST",
"path" : "/mock-endpoint",
"headers" : {
"user-agent" : [ "PostmanRuntime/7.42.0" ],
"postman-token" : [ "d858c7d9-d7b9-4ff0-bea9-255399791bcf" ],
"host" : [ "172.22.118.120:1081" ],
"content-type" : [ "application/json" ],
"content-length" : [ "152" ],
"connection" : [ "keep-alive" ],
"accept-encoding" : [ "gzip, deflate, br" ],
"accept" : [ "/" ]
},
"keepAlive" : true,
"secure" : false,
"protocol" : "HTTP_1_1",
"localAddress" : "127.0.0.1:1081",
"remoteAddress" : "127.0.0.1:37752",
"body" : {
"message" : "Your message content",
"to" : [ "+1234567890" ],
"from" : "+13473450776",
"media" : [ ],
"priority" : "default",
"tags" : { }
}
}

2024-10-02 17:03:32 5.15.0 INFO 1081 returning response:

{
"statusCode" : 200,
"headers" : {
"Content-Type" : [ "application/json" ]
},
"body" : {
"id" : "07348bcf-c348-4e22-adb2-f138cc348257",
"time" : "2024-10-02T16:03:32.868205485Z",
"message" : "",
"to" : "",
"from" : "1111111111111"
},
"delay" : {
"timeUnit" : "MILLISECONDS",
"value" : 0
}
}

for request:

{
"method" : "POST",
"path" : "/mock-endpoint",
"headers" : {
"user-agent" : [ "PostmanRuntime/7.42.0" ],
"postman-token" : [ "d858c7d9-d7b9-4ff0-bea9-255399791bcf" ],
"host" : [ "172.22.118.120:1081" ],
"content-type" : [ "application/json" ],
"content-length" : [ "152" ],
"connection" : [ "keep-alive" ],
"accept-encoding" : [ "gzip, deflate, br" ],
"accept" : [ "/" ]
},
"keepAlive" : true,
"secure" : false,
"protocol" : "HTTP_1_1",
"localAddress" : "127.0.0.1:1081",
"remoteAddress" : "127.0.0.1:37752",
"body" : {
"message" : "Your message content",
"to" : [ "+1234567890" ],
"from" : "+13473450776",
"media" : [ ],
"priority" : "default",
"tags" : { }
}
}

for action:

{
"template" : "{"statusCode":200,"headers":{"Content-Type":["application/json"]},"body":{"id":"{{ uuid }}","time":"{{ now_iso_8601 }}","message":"{{{jsonPath request.body '$.message'}}}","to":"{{{ request.body.to }}}","from":"1111111111111"},"delay":{"timeUnit":"MILLISECONDS"}}",
"templateType" : "MUSTACHE"
}

from expectation:

788c5024-0027-426a-a36e-859a4691f073

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