Skip to content

Let Discovery rules give the enum values an API really uses - #485

Merged
tnkuehne merged 2 commits into
mainfrom
discovery-enum-values
Nov 29, 2026
Merged

tnkuehne merged 2 commits into
mainfrom
discovery-enum-values

Conversation

@tnkuehne

Copy link
Copy Markdown
Contributor

Some Google Discovery documents list enum values that the API never sends or accepts. Search Console's description lists SITE_OWNER, QUERY and HOURLY_ALL. The API and its reference use siteOwner, query and hourly_all. Generated types with the listed values reject the real ones, and app code that compares against them never matches.

Change

  • Discovery rules get enumValues: for each Schema.field, every listed value maps to the value the API uses, or to null when the API never uses it. A field of an array maps its items. Enum descriptions follow their values.
  • The generator stops when the API adds a value the rules don't map, when a mapped value is gone, when the field no longer exists, or when a mapping drops every value. The mapping stays complete as the description changes.
  • Values are listed one by one rather than converted by a naming rule, because hourly_all follows no single pattern.

Testing

  • New generator test: mapping a field and an array field, dropping a value with its description, and all four errors.
  • templates/google-search-console (stacked above) uses the rule.

Some Discovery documents list enum values the API never sends or accepts:
Search Console's lists SITE_OWNER and QUERY, while the API and its reference
use siteOwner and query. The rules' new enumValues maps each listed value of
a field to the API's value, or drops it. The generator stops when the API adds
or removes a value, so the mapping stays complete.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 00e9feb Nov 29 2026, 08:48 AM

@tnkuehne
tnkuehne added this pull request to stack #486 November 29, 2026 08:34
@tnkuehne
tnkuehne merged commit 33d237f into main Nov 29, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the discovery-enum-values branch November 29, 2026 13:02
tnkuehne added a commit that referenced this pull request Nov 29, 2026
…ription (#473)

## Why

Search performance and index status are a common input for internal apps
and agents, and no template covers Google Search Console yet. Like
Sheets and Calendar, it only needs rules on top of the discovery
generator.

## What changes

**Google Search Console template** (`templates/google-search-console`)

- **Methods:** all ten methods of the Search Console API as typed
methods with field selections: `searchanalyticsQuery`,
`urlInspectionIndexInspect`,
`sitesList`/`sitesGet`/`sitesAdd`/`sitesDelete` and
`sitemapsList`/`sitemapsGet`/`sitemapsSubmit`/`sitemapsDelete`.
- **Not offered:** `urlTestingTools.mobileFriendlyTest.run`. Google
retired the Mobile-Friendly Test API in December 2023; the method is
still in the description but returns no results.
- **Approvals:** adding a property only adds it to the user's account
and runs at once by default. Submitting a sitemap changes what Google
crawls for every owner of the property and asks like an update. Removing
properties and sitemaps asks.
- **Scope:** `https://www.googleapis.com/auth/webmasters`, which adding
and removing need and every other method accepts. An account connected
with `webmasters.readonly` gets `permission_required`.
- **Properties:** `siteUrl` and `feedpath` are passed as Search Console
lists them (`sc-domain:example.com`, `https://example.com/`) and sent as
one encoded path segment each.
- **OAuth:** the organization's own Google OAuth client, like the other
Google templates.
- **Results:** `search_console_error` carries Google's message, status
and reasons. Rate limits including daily quotas (`dailyLimitExceeded`),
missing scopes, revoked tokens and responses over 8 MiB are handled like
in the other Google templates.
- **Enum values:** Google's description lists the enums of the
properties, sitemaps and search analytics methods in capitals
(`SITE_OWNER`, `QUERY`, `BY_PROPERTY`). The API sends the values its
reference lists (`siteOwner`, `query`, `byProperty`, `hourly_all`), so
the rules map them with `enumValues` from #485. URL inspection does use
capitals and keeps them. Values the reference leaves out, such as the
sitemap type `OCEANFRONT`, follow the other values' spelling.
- **Filter lists:** `filterLists` takes only `country` and `device`, the
dimensions Google supports for it.
- **Icon:** Google's official Search Console icon.

## Not run live

- `sitemapsSubmit` and `sitemapsDelete`. They use the same path encoding
and empty-response handling as `sitesAdd` and `sitesDelete`, which ran
live, and are covered by the template tests.

## Live run

Run against a real Google account through a deployed copy of the
template:

- `sitesList`, `sitesGet`, `sitemapsList`: Google returns `siteOwner`,
`siteFullUser`, sitemap type `sitemap` and content type `web`, the
mapped values.
- `searchanalyticsQuery` with `query`/`device` dimensions, `notContains`
filter with non-ASCII text, `filterLists` by country, `type: "web"`,
`aggregationType: "byProperty"`, `dataState: "all"`; and grouped by
`hour` with `hourly_all`. Google returns `responseAggregationType:
"byProperty"` and `metadata.firstIncompleteHour`, as the description
names it. Requests with the description's capitals (`QUERY`,
`BY_PROPERTY`) are accepted too; responses always use the mapped values.
- `urlInspectionIndexInspect`: returns `PASS`, `ALLOWED`,
`INDEXING_ALLOWED`, `SUCCESSFUL`, `MOBILE` in capitals, as the
description lists them.
- `sitesAdd` and `sitesDelete` with a non-ASCII property URL
(`https://live-test-größe.widefleet.com/`): both return no data; Google
stores the property under its punycode host and removes it again.
- `sitemapsSubmit` asks first at the default level; declining returns
`declined`.

## Tests

- Template tests: connection, encoded property and sitemap URLs with
non-ASCII text, search analytics and URL inspection, empty responses of
adding, submitting and removing, approvals per level, Google's errors,
rate limits, missing scopes, revoked tokens, refresh and disconnect.
- Generator tests pass. Google returns the description's methods in a
different order on each download, so regenerating reorders `src/api.ts`
and `src/schema.ts` without changing their content.
- Type tests: `permissionLevel === "siteOwner"` compiles;
`"SITE_OWNER"`, `dimensions: ["QUERY"]` and a `query` filter list don't.
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.

1 participant