Skip to content

feat: wildcard flatpath values referring to subresources#167

Merged
vchudnov-g merged 10 commits intomainfrom
wildcard-flatpath
Feb 19, 2026
Merged

feat: wildcard flatpath values referring to subresources#167
vchudnov-g merged 10 commits intomainfrom
wildcard-flatpath

Conversation

@vchudnov-g
Copy link
Contributor

The values of flatPath referring to subresources identified by {+someField} in path contain placeholders to subresource fields which are not fields of the request message where flatPath occurs, thus leading to errors when constructing and interpreting the synthetic proto's HTTP bindings. This change internally replaces those subresource-field references in flatPath with asterisks.

@vchudnov-g vchudnov-g marked this pull request as ready for review February 18, 2026 21:21
@vchudnov-g vchudnov-g requested review from a team and sergeiz-g as code owners February 18, 2026 21:21
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]+)\\}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("\\{[^}]*\\}", "*");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would probably use '[^}]+' instead of '[^}]*' as empty identified should be invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@vchudnov-g vchudnov-g merged commit 0b10e37 into main Feb 19, 2026
4 checks passed
@vchudnov-g vchudnov-g deleted the wildcard-flatpath branch February 19, 2026 01:07
@vchudnov-g vchudnov-g mentioned this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants