Skip to content

fix: add google discovery media upload operations#1271

Merged
RhysSullivan merged 1 commit into
UsefulSoftwareCo:mainfrom
batumilove:fix/google-discovery-media-upload
Jul 2, 2026
Merged

fix: add google discovery media upload operations#1271
RhysSullivan merged 1 commit into
UsefulSoftwareCo:mainfrom
batumilove:fix/google-discovery-media-upload

Conversation

@batumilove

Copy link
Copy Markdown
Contributor

Summary

Fix Google Discovery media upload modeling so upload-capable methods expose a binary request body instead of metadata-only JSON.

  • Decode supportsMediaUpload and mediaUpload from Google Discovery method definitions.
  • Generate separate simple media upload operations, for example files.createMedia and files.updateMedia.
  • Use the Discovery simple upload path under /upload/....
  • Preserve the method HTTP verb, so files.createMedia is POST and files.updateMedia is PATCH.
  • Add uploadType=media and an application/octet-stream request body, which is exposed as bodyBase64 by existing OpenAPI extraction.
  • Preserve the original metadata JSON operation unchanged.
  • Cover both single Discovery conversion and bundled Google Discovery conversion.

Why

Drive files.create advertised media upload support, but Executor generated only the metadata JSON operation. Calling it with uploadType=media had no binary/media body path and produced 0-byte Drive files.

Validation

  • bun run --cwd packages/plugins/google test -- src/sdk/discovery.test.ts
  • bun run --cwd packages/plugins/google test
  • bun run --cwd packages/plugins/openapi test -- src/sdk/non-json-body.test.ts src/sdk/index.test.ts
  • bun run format
  • bun run format:check
  • bun run lint
  • bunx tsgo --noEmit
  • git diff --check

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds Google Discovery media upload support by generating a separate OpenAPI operation (e.g., files.createMedia) alongside the existing metadata-only operation, using the simple upload path from the Discovery document. The change fixes Drive files.create producing 0-byte files when called with uploadType=media.

  • Adds DiscoveryMediaUpload / DiscoveryMediaUploadProtocol schemas and supportsMediaUpload / mediaUpload fields to DiscoveryMethod.
  • Introduces buildDiscoveryMediaUploadOperation, which emits an application/octet-stream request body, a locked-down uploadType=media query parameter, and an operation ID suffixed with Media; the function is wired into both single-document and bundle conversion loops.
  • Adds test coverage for single-document conversion (including path-parameter propagation and downstream extraction of bodyBase64) and bundled conversion.

Confidence Score: 5/5

The change is self-contained, adding new schema fields and a new operation-builder function without modifying any existing logic.

The new buildDiscoveryMediaUploadOperation mirrors the structure of buildDiscoveryOperation closely, guards all optional fields before access, and is exercised by two integration tests that validate the full pipeline down to bodyBase64 extraction. The upload URL uses rootUrl (not baseUrl), which is correct for the /upload/ Google endpoint pattern. No existing code paths were altered.

No files require special attention.

Important Files Changed

Filename Overview
packages/plugins/google/src/sdk/discovery.ts Adds DiscoveryMediaUpload schema types, buildDiscoveryMediaUploadOperation function, and wires it into both conversion entry points; logic is consistent with the existing buildDiscoveryOperation pattern and handles missing/undefined protocol paths safely.
packages/plugins/google/src/sdk/discovery.test.ts Adds two new integration tests: one for single-document conversion (verifying createMedia and updateMedia paths, parameters, requestBody, and downstream bodyBase64 extraction) and one for bundled conversion; requestBody is validated for the POST create case but not for the PATCH update case.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Discovery method loop] --> B{supportsMediaUpload == true\nAND mediaUpload defined?}
    B -- No --> C[Skip media upload]
    B -- Yes --> D{simple protocol path present?}
    D -- No --> C
    D -- Yes --> E[buildDiscoveryMediaUploadOperation]
    E --> F[Merge doc-level params\n+ method-level params]
    F --> G[Inject uploadType=media\nquery parameter]
    G --> H[Build operation:\noperationId toolPathMedia\npathTemplate = simple upload path\nbody = application/octet-stream]
    H --> I[normalizeDiscoveryPathTemplate\non upload path]
    I --> J[uniquePathKey to avoid conflicts]
    J --> K[Register in paths map]

    A --> L[buildDiscoveryOperation - original unchanged]
    L --> M[Register in paths map]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Discovery method loop] --> B{supportsMediaUpload == true\nAND mediaUpload defined?}
    B -- No --> C[Skip media upload]
    B -- Yes --> D{simple protocol path present?}
    D -- No --> C
    D -- Yes --> E[buildDiscoveryMediaUploadOperation]
    E --> F[Merge doc-level params\n+ method-level params]
    F --> G[Inject uploadType=media\nquery parameter]
    G --> H[Build operation:\noperationId toolPathMedia\npathTemplate = simple upload path\nbody = application/octet-stream]
    H --> I[normalizeDiscoveryPathTemplate\non upload path]
    I --> J[uniquePathKey to avoid conflicts]
    J --> K[Register in paths map]

    A --> L[buildDiscoveryOperation - original unchanged]
    L --> M[Register in paths map]
Loading

Reviews (3): Last reviewed commit: "fix: add google discovery media upload o..." | Re-trigger Greptile

Comment thread packages/plugins/google/src/sdk/discovery.ts
Comment thread packages/plugins/google/src/sdk/discovery.ts
@batumilove batumilove force-pushed the fix/google-discovery-media-upload branch from ed452f0 to a947d90 Compare July 2, 2026 15:02
@batumilove batumilove force-pushed the fix/google-discovery-media-upload branch from a947d90 to e1c04cd Compare July 2, 2026 15:16
@RhysSullivan

Copy link
Copy Markdown
Collaborator

thanks!

@RhysSullivan RhysSullivan merged commit 9c7e4a6 into UsefulSoftwareCo:main Jul 2, 2026
35 of 37 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