-
Notifications
You must be signed in to change notification settings - Fork 32
chore: support complex resource identifiers #125
Conversation
Codecov Report
@@ Coverage Diff @@
## master #125 +/- ##
============================================
+ Coverage 60.93% 63.96% +3.02%
- Complexity 148 163 +15
============================================
Files 14 14
Lines 622 702 +80
Branches 92 112 +20
============================================
+ Hits 379 449 +70
- Misses 217 219 +2
- Partials 26 34 +8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of complex logic, which is hard to comprehend and "compile" in head =) (especially the parseComplexResourceId()
method), so given the test cases, I trust that it works correctly.
Basically looks good, with a few questions:
-
It is probably a silly question, but I'm wondering if in the implementation we replaced the complex delimiters with
/
, remembering the mapping between the original delimiters and "fake" slashes, then propagated that to the existing PathTemplate logic (which knows only slashes), and then used the saved mapping, if needed, to reverse that inPathTemplate.match()
implementation. Does it have a chance to work? If yes, it can result in much simpler implementation.
Or, in other words: are the "new" delimiters just another syntax for delimiters or is there a fundamental difference between/{a}/{b}
and/{a}~{b}
formats (does~
put{a}
and{b}
in some sort of different relation compared to/
separator)? -
This is slightly related to the question 1 (because it may make 1 more feasible). Should we forbade usage of a delimiter character in the body of the resoruce name? (see a comment for one of the test cases for more details).
Truth.assertThat(match.get("project")).isEqualTo("project-123"); | ||
Truth.assertThat(match.get("zone_a")).isEqualTo("europe-west3-c"); | ||
Truth.assertThat(match.get("zone_b")).isEqualTo("us-east3-a"); | ||
Truth.assertThat(match.get("zone_c")).isEqualTo("us"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look like it uses greedy approach and for the last ambiguous segment ({zone_c}-{zone_d}
), when provided with us-west2-b-europe-west2-b
input it treats the stuff before the first hyphen (us
) as zone_c
and everything else as zone_d
.
This ambiguity looks like a real problem. Even thought the implementation behaves predictably and reasonably, looks like us-west2-b-europe-west2-b
should be split as zone_c=us-west2-b
and zone_d=europe-west2-b
.
Should we forbade a character in the body if the same character uses as a splitter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a spec question, let's take this discussion over there. @chrisdunelm FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a known potential problem.
The spec currently states that it is the responsibility of the API producer to ensure that any split character(s) are not present in the variables. As things are now, I consider this sufficient.
An alternative would be to verify that no parsed variable values contain any of the [used] split character(s); but I think this would be too much,
Responding to @vam-google's comment:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The travis jobs are failing on formatting validation. Please run ./gradlew googleJavaFormat
to automatically format the files and push updated files.
LGTM, to not block this work, assuming build jobs pass and the spec "ambiguity" (the hyphen thing) is resolved/clarified in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once CI passes.
* chore: support complex resource identifiers * remove debug printf * fix: clean up PathTemplate.java and tests
Add support for the non-slash resource name separators. That is, "-", "~", "_", ".". These changes are needed for gapic-generator.
Relevant issue here.