wiremock / wiremock-state-extension

Adds support for transporting state across different API mock stubs
Apache License 2.0
16 stars 5 forks source link

Full bodies have the quotes replaced with " when being retrieved #115

Closed nsfrias closed 9 months ago

nsfrias commented 9 months ago

Proposal

The retrieved response contains " instead of " when a full body is stored with quotes.

{
    "id": "ec079c49-75aa-4864-aaf9-3931ff71f3a2",
    "description": "Somevalue",
    "createdTs": "2024-01-1610: 28: 30+0000"
}

Note: I have not tried to record other state with quotes.

Reproduction steps

This are my stubs:

{
    "request": {
        "method": "POST",
        "urlPattern": "/example"
    },
    "response": {
        "status": 200,
        "bodyFileName": "body.txt" 
    },
    "serveEventListeners": [
        {
            "name": "recordState",
            "parameters": {
                "context": "{{jsonPath response.body '$.id'}}",
                "state": {
                    "fullBody": "{{jsonPath response.body '$'}}"
                }
            }
        }
    ]
}
{
    "priority": 10,
    "request": {
        "method": "GET",
        "urlPattern": "/example/.+"
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "body": "{{{state context=request.pathSegments.[1] property='fullBody'}}}"
    }
}

The body is stored in a separate file for clarity:

{
    "id": "{{randomValue type='UUID'}}",
    "description": "Some value",
    "createdTs": "{{now format='yyyy-MM-dd HH:mm:ssZ'}}"
}

I built the standalone jar locally using the code from version 0.6.1 .

I have send a tar.gz file that is ready to reproduce all you need to do is to:

tar -xvzf bug_report.tar.gz
cd bug_report
docker-compose up
curl -X POST http://localhost:11091/example

# copy the returned id and replace on the following GET

curl -X GET http://localhost:11091/example/id

bug_report.tar.gz

References

No response

dirkbolte commented 9 months ago

will have a look.

nsfrias commented 9 months ago

Thank you for the prompt reply. 👍

dirkbolte commented 9 months ago

Was able to reproduce it but for me it turned out to be a documentation error: instead of {{ in your eventListener, {{{ is needed:

"fullBody": "{{jsonPath response.body '$'}}" -> "fullBody": "{{{jsonPath response.body '$'}}}"

The PR I created tested the behavior and updates the documentation. Can you check whether it works for you as well?

nsfrias commented 9 months ago

Thank you very much for your quick reply @dirkbolte