feat: wildcard flatpath values referring to subresources#167
feat: wildcard flatpath values referring to subresources#167vchudnov-g merged 10 commits intomainfrom
Conversation
ff7073f to
d985525
Compare
| public static String accomodatePathSubresources(String path, String flatPath) { | ||
| // Regex to find {+FOO}, where FOO is alphanumeric. | ||
| // We escape the braces and the plus sign. We capture FOO. | ||
| Pattern tokenPattern = Pattern.compile("\\{\\+([a-zA-Z0-9]+)\\}"); |
There was a problem hiding this comment.
super nit: Since the pattern is not going to change, we can move it to a static private variable so we don't have to parse it over and over again
There was a problem hiding this comment.
Good point! Done.
| // Modify subresource | ||
| // Regex: Opening brace {, followed by any character that is NOT a closing brace, followed by } | ||
| // This ensures we stop at the *next* closing brace. | ||
| String modifiedSubresource = subresource.replaceAll("\\{[^}]*\\}", "*"); |
There was a problem hiding this comment.
nit: I would probably use '[^}]+' instead of '[^}]*' as empty identified should be invalid
There was a problem hiding this comment.
This is a replaceAll, so making that change will not rignal; it will simply refuse to flag that instance. I made the change anyway, becasue the empty placehodler should signal downstream in the generators or GAPICs about this anomalous condition. Though there's an argument to be made to just convert {} to *.
Added a test case to capture the behavior.
| @Test | ||
| public void accomodatePathSubresources_multipleSubresourceBraces() { | ||
| // Mix of literal and {} in subresource | ||
| assertEquals( |
There was a problem hiding this comment.
nit: do we want to include another test case with the slashes (just in case since slashes are special characters and we want to make sure those will be correctly handled by the regex / replacement logic? Something like:
assertEquals(
"prefix/{name=a//c//e}/suffix",
Method.accomodatePathSubresources("prefix/{+name}/suffix", "prefix/a/{b}/c/{d}/e/suffix"));
5e38869 to
bd74ffa
Compare
The values of
flatPathreferring to subresources identified by{+someField}inpathcontain placeholders to subresource fields which are not fields of the request message whereflatPathoccurs, thus leading to errors when constructing and interpreting the synthetic proto's HTTP bindings. This change internally replaces those subresource-field references inflatPathwith asterisks.