opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

Added support for URL pattern matching #17

Closed codeperfector closed 7 years ago

codeperfector commented 8 years ago

Added regex based pattern matching for incoming request URLs that allows extracted regex groups to be included in variable replacements. This allows values to be extracted from query parameters, etc in the URL and be included in the response body.

codeperfector commented 8 years ago

@tranhungt can you please take a look. Thanks!

tranhungt commented 8 years ago

@waynemz Thanks for the submission. This is a great idea.

A suggestion though, why don't we use named regex groups to parse the URL instead of passing in the parameters 'groupNames'? http://stackoverflow.com/questions/415580/regex-named-groups-in-java

It would help reduce fragility/coupling of the regex url matcher and the named groups.

codeperfector commented 8 years ago

@tranhungt thanks for the feedback. I'll make the change to the static imports. Will test with named capturing groups to see if they work well. I could have support for both named capturing as well as 'groupNames' parameter with a preference for groupNames if present. Any opinions on having both?

tranhungt commented 8 years ago

Great, thanks @waynemz.

Coming from Python, I think it's more clear for the end user if there's only one correct way to use named groups. Giving multiple options may add cruft to our code, make it harder to maintain, and will be confusing or prone to implementation errors to end users.

Since the user has to specify the named groups in the urlRegex field already, it's common practice to use named groups in regex matching. We'll be sure to show how to use named groups in the documentation so it'll be clear how it works.

codeperfector commented 7 years ago

@tranhungt I added the requested changes. Please review. Note that you may see some code from conflict resolution since I had a conflict with another PR.

tranhungt commented 7 years ago

Awesome. Thanks @waynemz . Will look soon.

codeperfector commented 7 years ago

@tranhungt Please take a look and approve.

tranhungt commented 7 years ago

@waynemz Thanks for the reminder! This looks great. Thanks for adding the feature. :1st_place_medal: