Skip to content

fix: handle duplicate OAuth scope enum variants (unblocks script API)#565

Merged
Byron merged 2 commits intoByron:mainfrom
l1n:unblock-script-api
Jan 1, 2026
Merged

fix: handle duplicate OAuth scope enum variants (unblocks script API)#565
Byron merged 2 commits intoByron:mainfrom
l1n:unblock-script-api

Conversation

@l1n
Copy link
Copy Markdown
Contributor

@l1n l1n commented Dec 25, 2025

Summary

This PR fixes a code generation bug that caused duplicate Rust enum variants when OAuth scope URLs share the same final path segment. This unblocks generation of the google-script1 crate.

Problem

The Apps Script API has two OAuth scopes:

  • https://www.google.com/calendar/feeds
  • https://www.google.com/m8/feeds

The generator extracts the last path segment (feeds) and converts it to a CamelCase enum variant (Feed). Since both URLs have the same final segment, this created duplicate enum variants:

pub enum Scope {
    Feed,  // calendar/feeds
    Feed,  // m8/feeds - DUPLICATE!
}

This caused compilation to fail with E0428: the name 'Feed' is defined multiple times.

Solution

  1. Removed script from the blacklist in etc/api/shared.yaml

    • The original comment said "redefinition of type (Feed)" but this was misleading — it's about scope variants, not schema types
  2. Added deduplication logic to src/generator/templates/api/lib/lib.mako

    • Pre-processes all scope URLs to detect duplicate variant names
    • For duplicates, uses more of the URL path to create unique names

Result

The generated code now has unique variant names:

pub enum Scope {
    CalendarFeeds,  // https://www.google.com/calendar/feeds
    M8Feeds,        // https://www.google.com/m8/feeds
    // ...
}

Testing

  • Generated google-script1 successfully
  • cargo check passes on the generated crate

🤖 Generated with Claude Code

l1n and others added 2 commits December 25, 2025 00:26
The code generator creates Rust enum variants from OAuth scope URLs by
extracting the last path segment. When two scopes have the same final
segment (e.g., `/calendar/feeds` and `/m8/feeds` both become `Feed`),
this caused duplicate enum variants and compilation failures.

This fix:
1. Removes `script` from the blacklist in shared.yaml (the original
   blocker comment about "Feed" type was actually about scope variants)
2. Adds deduplication logic to lib.mako that detects duplicate variant
   names and uses more path segments to disambiguate them

For the Apps Script API, this changes:
- `Feed` (calendar) -> `CalendarFeeds`
- `Feed` (contacts) -> `M8Feeds`

This unblocks generation of google-script1 v7.0.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Validated with `make script1-cargo ARGS=check`
@Byron Byron force-pushed the unblock-script-api branch from f04f835 to cc7794d Compare January 1, 2026 15:56
@Byron
Copy link
Copy Markdown
Owner

Byron commented Jan 1, 2026

Thanks a lot, much appreciated!

Please note that I regenerated the script1 crate myself to avoid having to review 7k lines of code 😅.

@Byron Byron merged commit 3c89d7e into Byron:main Jan 1, 2026
6 checks passed
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.

2 participants