GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: support complex resource identifiers by miraleung · Pull Request #125 · googleapis/api-common-java

This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Conversation

@miraleung

@miraleung miraleung commented May 6, 2020

Copy link
Copy Markdown
Contributor

Add support for the non-slash resource name separators. That is, "-", "~", "_", ".". These changes are needed for gapic-generator.

Relevant issue here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@miraleung
chore: support complex resource identifiers
fcbabd0
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 6, 2020
@miraleung miraleung assigned chrisdunelm and vam-google May 6, 2020
@codecov

codecov Bot commented May 6, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #125 into master will increase coverage by 3.02%.
The diff coverage is 88.33%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...java/com/google/api/pathtemplate/PathTemplate.java 69.06% <88.33%> (+4.21%) 106.00 <7.00> (+15.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6e9dad...12b22f3. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miraleung
remove debug printf
e2181f6
@miraleung miraleung mentioned this pull request May 6, 2020
chore: add tests for complex resource IDs googleapis/gapic-generator#3190
Merged
@vam-google
vam-google self-requested a review May 6, 2020 15:12
@miraleung
miraleung requested a review from chrisdunelm May 6, 2020 21:20
vam-google
vam-google reviewed May 6, 2020
View reviewed changes

@vam-google vam-google left a comment

Copy link
Copy Markdown
Contributor

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:

  1. 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 in PathTemplate.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)?

  2. 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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/pathtemplate/PathTemplate.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/test/java/com/google/api/pathtemplate/PathTemplateTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/test/java/com/google/api/pathtemplate/PathTemplateTest.java
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");

@vam-google vam-google May 6, 2020

Copy link
Copy Markdown
Contributor

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@miraleung miraleung May 7, 2020

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chrisdunelm chrisdunelm May 13, 2020

Copy link
Copy Markdown

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,

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@miraleung
fix: clean up PathTemplate.java and tests
12b22f3
@miraleung

miraleung commented May 7, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Responding to @vam-google's comment:

  1. Mixing up the existing "/" and complex resource ID delimiter parsing logic risks introducing error edge cases. For example, if someone passes in projects/{project}-zones/{zone_a}/{zone_b} where they meant projects/{project}/zones/{zone_a}-{zone_b}, the former could result in a valid parsing under the mixed implementation. Not only would we require additional logic to separate out literals and IDs (which could become even more complex), we'd risk having literals being parsed in as IDs, and vice-versa.
    One advantage of the current set-up is that it's easy to isolate and toggle complex resource ID parsing on/off, or add in a whitelist for the relevant clients if that becomes necessary.
  2. PTAL at the comment here.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vam-google
vam-google approved these changes May 11, 2020
View reviewed changes

@vam-google vam-google left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@miraleung miraleung added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels May 12, 2020
chrisdunelm
chrisdunelm approved these changes May 13, 2020
View reviewed changes

@chrisdunelm chrisdunelm left a comment

Copy link
Copy Markdown

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-fenster alexander-fenster added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels May 13, 2020
@miraleung
miraleung merged commit 140d26d into master May 13, 2020
@miraleung
miraleung deleted the miraleung/resource_names branch May 13, 2020 22:10
@chingor13 chingor13 mentioned this pull request May 26, 2020
chore: release v1.9.1 #144
Merged
miraleung added a commit that referenced this pull request Jun 3, 2020
@miraleung
chore: support complex resource identifiers (#125)
b98fb5b
* chore: support complex resource identifiers

* remove debug printf

* fix: clean up PathTemplate.java and tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@chrisdunelm chrisdunelm chrisdunelm approved these changes
@vam-google vam-google vam-google approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@chrisdunelm chrisdunelm

@vam-google vam-google

Labels

cla: yes This human has signed the Contributor License Agreement. kokoro:force-run Add this label to force Kokoro to re-run the tests.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@miraleung @chrisdunelm @vam-google @alexander-fenster @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.