https://linen.dev logo
#general
Title
# general
r

Remi David

02/05/2023, 11:02 PM
Newbie question here: I have an example for a response where one of the fields is of format uuid. it is returned by a GET request with an in path parameter. I'd like this parameter to match the one in the response. ex: /v1/products/abcd should return the example where the id is abcd. When I import in WireMock the stubs get assigned a random uuid in the url instead of the examples I have provided.
r

Rob Elliot

02/06/2023, 10:58 AM
What are you importing? An OpenAPI spec?
r

Remi David

02/08/2023, 10:39 PM
Yes
"/v1/products/1234" as endpoint and the response examples I have two. { "Id":"1234". } { "Id":"4567" } How do I connect the request example to the response. I know this is probably not the right forum for this. I appologize for it
r

Rob Elliot

02/09/2023, 10:12 AM
I'm afraid the import can't do that for you. What you probably want to do is edit the stub to: • use a regex to match the id in the path (e.g.
/v1/products/[0-9]+
) - you'll need to change the match type • use response templating • use the third element of the path as the id in the response
Are you using WireMock Cloud, or WireMock Open Source?
r

Remi David

02/10/2023, 2:12 PM
Cloud
r

Rob Elliot

02/10/2023, 2:13 PM
OK - have a look at: https://docs.wiremock.io/docs/request-matching/url/ and https://docs.wiremock.io/docs/response-templating/basics/ for details on how to match using a URL path regex, and then use part of the path in the response
r

Remi David

02/10/2023, 2:26 PM
Thank you, I'll check it out
Ok I looked at the documentation but the issue I'm having is that my in: path parameter (/v1/products/{productId}) has an example of 0df3e2e5-bc2e-4e52-a8cf-47161abe88. When I put it in other tools like online swagger editor I see that the example is taken in consideration but when I import into WireMock it always get a random uuid instead. Even if I use regex, it is pretty hard to guess which uuid will be generated and I need to discern between two examples
The only way I have been able to do it is to import my swagger and modify the stubs manually. This is not so bad except I am in the beginning of defining the schemas and they are changing quite often