Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute API v1: xxxResourceName.parse throws ValidationException #3604

Closed
dtretyakov opened this issue Aug 24, 2018 · 1 comment · Fixed by googleapis/gapic-generator#2478 or #4213
Closed
Assignees
Labels
api: compute Issues related to the Compute Engine API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dtretyakov
Copy link

Currently all parse() methods in xxxResourceName classes expect that input string will be formatted like projects/{project}/..., but data returned from APIs contains URL prefixes like https://www.googleapis.com/compute/v1/projects/... and as result parsing fails with ValidationException.

Example

Receive instance details where:

instance.zone = https://www.googleapis.com/compute/v1/projects/project-123/zones/europe-west3-c

Then when trying to parse it with ProjectZoneName.parse(instance.zone) will cause the following exception:

ProjectZoneName.parse: formattedString not in valid format: Parameter "https://www.googleapis.com/compute/v1/projects/project-123/zones/europe-west3-c" must be in the form "projects/{project=*}/zones/{zone=*}"
@andreamlin andreamlin self-assigned this Aug 24, 2018
@andreamlin andreamlin added api: compute Issues related to the Compute Engine API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 24, 2018
@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Aug 25, 2018
@yihanzhen yihanzhen added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Aug 27, 2018
@JustinBeckwith JustinBeckwith removed the triage me I really want to be triaged. label Aug 27, 2018
@yihanzhen
Copy link
Contributor

@andreamlin I added priotity: p2 to remove the triage me label. Feel free to bump to p1 if you find it necessary.

andreamlin added a commit to googleapis/gapic-generator that referenced this issue Dec 11, 2018
Partially addresses googleapis/google-cloud-java#3604.

Don't force pathtemplate strings to start with a literal string.

The status quo, for path templates, is to magically append a literal string to templated paths that begin with a bracketed string, e.g. the path {project}/zones/{zone} is rendered as projects/{project}/zones/{zone}. I don't remember exactly why we decided to do this, though it may have been related to purity of usage of PathTemplates, where all existing Google grpc path templates start with a projects (or possibly organizations) substring.

More importantly, this PR allows us to parse a resource string returned from the server (see issue googleapis/google-cloud-java#3604), which often looks like https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}. The compute.v1.json Discovery API specifies that the baseUrl is exactly https://www.googleapis.com/compute/v1/projects. We can then take a resource string from the server, remove the given baseUrl prefix, and then parse the remaining suffix {project}/zones/{zone} into a ProjectsZoneName.

See googleapis/google-cloud-java#3899 and googleapis/discovery-artifact-manager#95 for the resulting surface diffs from this generator change.
andreamlin added a commit to googleapis/gapic-generator that referenced this issue Dec 13, 2018
dtretyakov added a commit to JetBrains/teamcity-google-agent that referenced this issue Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: compute Issues related to the Compute Engine API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants