Java – how to specify optional query parameters
•
Java
I defined query parameters in the contract I need this parameter to be optional:
method 'GET' url($(regex(urlRegex))) { queryParameters { parameter 'fitler': $(stub(regex(filterRegex))) } }
I want this contract to work with things like / my / sample / URL? Filter = two URLs for filters like some filter expression, without filter parameters like / my / sample / url
How can I do this? Is this even possible?
Solution
So far, this is not clearly defined in the wirelock specification However, you can use regular expressions to solve this problem by specifying the URL (in the JSON stub) using the urlpathpattern attribute See the example below
{ "request": { "method": "GET","urlPathPattern": "/myapp/users(\\?((a-zA-Z\\d\\_\\-)+\\=(a-zA-Z\\d\\_\\-)+)(\\&(a-zA-Z\\d\\_\\-)+\\=(a-zA-Z\\d\\_\\-)+)+)?" },"response": { "status": 200,"bodyFileName": "users.json","headers": { "Content-Type": "application/json" } } }
Look at the optional section at the end of the URL, which looks for a typical URL query structure Well, I've tried to run smoothly in the cable
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码