Skip to content

feat: implement <api>:<version> syntax for unlisted Discovery APIs#709

Open
nuthalapativarun wants to merge 2 commits intogoogleworkspace:mainfrom
nuthalapativarun:feat/unlisted-api-colon-syntax
Open

feat: implement <api>:<version> syntax for unlisted Discovery APIs#709
nuthalapativarun wants to merge 2 commits intogoogleworkspace:mainfrom
nuthalapativarun:feat/unlisted-api-colon-syntax

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Problem

The error message for unknown services has long advertised:

Use <api>:<version> syntax for unlisted APIs.

But parse_service_and_version() always called resolve_service() and failed for any name not in the hardcoded SERVICES registry — the syntax had no effect for unlisted APIs.

$ gws admob:v1 --help
{
  "error": {
    "code": 400,
    "message": "Unknown service 'admob'. Known services: drive, sheets, ... Use '<api>:<version>' syntax for unlisted APIs.",
  }
}

Fix

In parse_service_and_version(), when split_once(':') produces (svc, ver) and resolve_service(svc) returns Err, bypass the registry and return (svc, ver) directly. The Discovery fetch in fetch_discovery_document() already validates both identifiers via validate_api_identifier() before embedding them in the URL, so no additional sanitisation is needed.

# After this fix:
$ gws admob:v1 accounts list --params '{"pageSize": 5}'
# → fetches https://www.googleapis.com/discovery/v1/apis/admob/v1/rest and proceeds

Scope of the bypass: only <api>:<version> positional syntax triggers the bypass. The --api-version flag alone does not bypass the registry for unknown services — a version must be part of the positional argument.

Tests

Five new unit tests in main.rs:

Test What it checks
test_parse_service_and_version_known_service Registry lookup still works for known services
test_parse_service_and_version_known_service_colon_override Colon syntax overrides version for known services
test_parse_service_and_version_unlisted_api_colon_syntax admob:v1 resolves to ("admob", "v1")
test_parse_service_and_version_unlisted_api_no_version_errors admob (no version) still returns an error
test_parse_service_and_version_api_version_flag_unlisted --api-version alone does not bypass the registry

Fixes #670

The error message has long advertised:
  "Use '<api>:<version>' syntax for unlisted APIs."
but parse_service_and_version() always called resolve_service() and failed
for any name not in the hardcoded SERVICES registry.

Fix: when split_once(':') produces (svc, ver) and resolve_service(svc)
returns Err, bypass the registry and return (svc, ver) directly.
fetch_discovery_document() already validates both identifiers via
validate_api_identifier() before embedding them in the Discovery URL, so
no additional sanitisation is needed here.

The --api-version flag alone does not bypass the registry — a version must
be supplied as part of the '<api>:<version>' positional argument, keeping
the change minimal and consistent with existing flag semantics.

Adds five unit tests covering known services, colon-version override,
unlisted-API bypass, and the error path for missing versions.

Fixes googleworkspace#670
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 12, 2026

🦋 Changeset detected

Latest commit: 66a912b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables support for unlisted Google Discovery APIs by allowing the CLI to bypass its internal service registry when a specific : syntax is used. This change aligns the tool's behavior with its existing error messages, providing a more flexible way to interact with APIs that are not explicitly registered in the codebase.

Highlights

  • Registry Bypass: Implemented a mechanism to bypass the hardcoded service registry when the user provides an explicit : syntax, allowing for unlisted Discovery APIs to be used.
  • Validation Logic: Updated the service parsing logic to verify if a version was provided via colon syntax before deciding to bypass the registry, ensuring that standard error handling remains for unknown services without versions.
  • Testing: Added five new unit tests to verify registry lookup behavior, colon syntax overrides, and correct error handling for unlisted APIs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Apr 12, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables the : syntax to support unlisted Discovery APIs, allowing the CLI to bypass the service registry when a version is explicitly provided. The implementation updates the parse_service_and_version function and adds unit tests for various edge cases. Feedback points out that the bypass flag should be set whenever the colon syntax is used, even if a version override from a flag is already present, to ensure unlisted APIs are correctly handled in all scenarios.

When --api-version is supplied alongside <api>:<version>, the previous code
only set explicit_version_from_colon when version_override was None, so the
unlisted-API bypass never fired in that combination. Move the flag assignment
outside the version_override guard so the bypass is always active when the
colon syntax is present.
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for the : syntax, enabling the CLI to fetch unlisted Discovery APIs directly without a registry entry. The parse_service_and_version function was updated to handle this bypass logic, and several unit tests were added to cover known services, version overrides, and the precedence of the --api-version flag. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<api>:<version> syntax for unlisted APIs is advertised but not implemented

2 participants