mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
GuidWildcardMatcher to match on GUIDs #386
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @brogdogg on GitHub (Nov 17, 2021).
Is your feature request related to a problem? Please describe.
I have been using the
RegexMatcherto do matches for paths with GUIDs, but after a while thePatternin the JSON mappings becomes unwieldly long in length when a few GUIDs are used.Describe the solution you'd like
Would like a matcher to allow for matching a GUID (mostly in the
Path). For example:Path-http://localhost/v1.0/4a7eaad5-bbe7-4579-bb0b-7c85352fe1b6/task/edef5b4a-33bb-4920-bb42-1d5e6283984eJSON mapping:
Where the tokens used in the pattern match up with the
GUID.ToString(string? format)method as described here.Describe alternatives you've considered
None - I can use the
RegexMatcherif the feature is not accepted.Is your feature request supported by WireMock (java version)? Please provide details.
I do not believe this is supported in the java version (I did a search and couldn't find anything that I could see)
@StefH commented on GitHub (Nov 17, 2021):
It would also be an option to update the wildcard matcher.
Currently the wildcard matcher supports a
*. Maybe when adding logic to understand alsoGUID(D)could be an option...Just thinking....
@brogdogg commented on GitHub (Nov 17, 2021):
True, I mean could it be a more general matcher available in JSON as well? I forked and trying to play with it to see.
@brogdogg commented on GitHub (Nov 17, 2021):
OK, after playing I see what you mean by updating the wildcard matcher, since it extends
RegexMatcher. I was trying something like this:and was able to get things working.
My only thought about putting it in the
WildcardMatcheris I would not think to look there for a GUID matcher. But I'm honestly having a difficult time thinking of a better solution. Creating a newGuidMatcherand extendingRegexMatcheris where I first went, which would work but it ain't immediately clear you have fullRegexcapabilities on the matcher.Anyways, thanks for the consideration.
@StefH commented on GitHub (Nov 17, 2021):
What we also could do is 'extending' the RegEx specification by adding GUID, GUIDN or GUIDP.
So like
\dmatches a digit, the\GUIDshould match a Guid.So maybe new logic should be moved to a separate helper NuGet / project / class and then replace all logic in WireMock.Net which uses Regex, by this new "RegexExtended".
?
@brogdogg commented on GitHub (Nov 18, 2021):
I like the idea. I took a look at the RegexParser. ScanBackslash method and it is quite involved and isn't really built for extensibility, which would result in divergent code paths. So doesn't feel like a longterm solution? Unless could be added to the main library.
Anyways, if it were to be done maybe something similar to the
\p{}, could do something like\g{}(\Gis already used).@StefH commented on GitHub (Nov 18, 2021):
I just meant that we don't need to write parser code, just use your replace logic, like:
@brogdogg commented on GitHub (Nov 18, 2021):
I see what you mean.
@brogdogg commented on GitHub (Nov 18, 2021):
OK, I got a library where I have most of the work done. Will try to package into a nuget later and publish.
@StefH commented on GitHub (Nov 18, 2021):
Cool.
However, if it's only a single class file, maybe it's better to just include it in this project first.
@brogdogg commented on GitHub (Nov 18, 2021):
Meh... it could be useful for others too I suppose.
@brogdogg commented on GitHub (Nov 18, 2021):
I could try to integrate it on my fork as a single class integrated and put up a PR. Would that be helpful?
@StefH commented on GitHub (Nov 28, 2021):
Hello @brogdogg;
Did you achieve any progress on this?
@brogdogg commented on GitHub (Nov 29, 2021):
@StefH I had it done and then realized my line endings got jacked... and then Thanksgiving happened, so took a break. Will try to figure out my line endings and get it ready.
@brogdogg commented on GitHub (Dec 13, 2021):
Thanks @StefH , I was able to pull the latest version and use this feature. Thanks again for being so open to my feature suggestion.