Skip to content

Generate the OneDrive template from Microsoft Graph's OpenAPI description - #322

Merged
tnkuehne merged 13 commits into
feat/github-templatefrom
feat/onedrive-template
Nov 23, 2026
Merged

tnkuehne merged 13 commits into
feat/github-templatefrom
feat/onedrive-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

The OneDrive template offers three hand-written methods: list files, search files, get a download link. Uploading, moving, sharing or restoring files needs a template change. Microsoft Graph publishes an OpenAPI description, but it covers all of Microsoft 365: 18,094 operations and 5,367 schemas. A template can only offer a chosen part of it. Outlook, Jira, Confluence and other REST APIs need the same kind of generator.

What changes

OpenAPI generator (packages/template-generator/src/openapi.ts)

  • Rules: a template lists the operations it offers by operation ID, with a method name and, for every operation that isn't a GET, the change it makes. The generator stops on stale IDs, on changes without a kind and on taken names.
  • Input: reads JSON or YAML. yaml is already a dependency of the app builder and the control plane.
  • Types:
    • Only the types the offered operations reach are emitted: 60 of Graph's 5,367.
    • Graph's prefix is left out of type names: microsoft.graph.driveItem becomes DriveItem.
    • allOf becomes an intersection, and Graph's nullable anyOf becomes T | null.
    • Unions are flattened. String values that string already covers are dropped.
    • Navigation properties are left out: Graph only returns them when expanded.
    • Required OData annotations such as @odata.type are optional, because the server adds them.
  • Inputs:
    • Path parameters get camelCase names: drive-id becomes driveId.
    • Query parameters keep the API's names, such as $top and $select.
    • Header parameters aren't offered.
  • Parameters: an operation's parameter replaces the path's parameter with the same name and place. Path parameters are never typed as null, and nullable component types keep null.
  • Generation stops on:
    • two inputs of one operation with the same name;
    • object query parameters;
    • clashing type names, checked only among the schemas the offered operations reach;
    • schema names that shadow BinaryContent, UploadContent or the service class.
  • JSON without a schema: a JSON body or result without one takes any JSON.
  • Paging: operations Graph marks as pageable accept either their first-page arguments or only a nextLink. It must be an address on the API's origin, such as @odata.nextLink or @odata.deltaLink.

Shared REST runtime (runtime/rest.ts)

  • Requests: builds them from the generated operation table:
    • path parameters are encoded;
    • quoted OData values double their quotes, as in search(q='it''s');
    • lists are repeated or comma-joined, as the description says;
    • arguments are checked before anything is sent.
  • Binary responses:
    • a redirect becomes { downloadUrl }, so the app never fetches the file;
    • other content up to 8 MiB is returned as { contentType, data }.
  • Checks before sending: a missing required body is rejected, and so are path values . and .., which would move the request to another path. The Google runtime rejects them too.
  • Size limit: JSON responses and file content larger than 8 MiB give too_large, as in the other templates.
  • Arguments: optional arguments passed as undefined are left out.
  • Text bodies: sent with their contentType.

OneDrive template

  • Methods: 39 typed methods: drives, root, items and children, search, recent items, delta, content download and upload, upload sessions, thumbnails, previews, versions, check-in and check-out, permissions, links, invitations, and following. scripts/operations.ts names the Graph operation behind each one. Graph's sharedWithMe is left out: Microsoft stops it returning data after November 2026.

  • Approvals: per-user approval level, like in the other templates.

    • Creating a folder, copying, following and previews are create.
    • Renaming or moving, replacing content, restoring, creating sharing links and changing permissions are update.
    • Deleting is delete.
    • Inviting people, which emails them, is send.
  • Scope: Files.ReadWrite.All instead of Files.Read. An account connected with fewer permissions gets permission_required from every method and from connectionStatus. Graph scopes are accepted with or without their resource prefix.

  • Errors:

    Graph answer Result
    error body graph_error with Graph's code, message and HTTP status
    429, or 503 with Retry-After rate_limited
    401 reconnect_required
  • Removed: listFiles, searchFiles and getDownloadUrl, with their helpers.

  • template.md describes addressing by drive and item ID, OData options, paging, downloads and uploads, approvals, results and how to offer more operations.

Managed OAuth

A managed microsoft client only grants the scopes its scopes setting allows. Installations that offer managed OAuth for Microsoft must allow Files.ReadWrite.All there. Until they do, starting a managed connection fails with "The requested scopes are not allowed for this client". Installations with their own Entra application need the delegated Files.ReadWrite.All permission.

Connection page

Connected state, with the same approval form as the other templates.

Before After

Not shown: the disconnected and setup-required states. They only change their description text.

Testing

  • pnpm check
  • Generator: offered operations and reached types, prefix stripping, navigation properties, annotations, nullable references, paging, binary content and text bodies, YAML input, and stale or invalid rules.
  • Runtime: paths, OData quotes, query lists, page links on other origins, text bodies, unknown arguments, download redirects and the content limit.
  • OneDrive template against a mocked Graph:
    • typed requests and URLs;
    • paging through nextLink;
    • download addresses that are never fetched;
    • approvals for create, update and delete;
    • missing permissions;
    • Graph errors and throttling;
    • token refresh, outages and callback checks.
  • Type tests: the README example compiles; unknown arguments and wrong query types don't.
  • Managed OAuth tests: run against the new scope and methods.
  • Generating from Graph's YAML and from its JSON gives the same files. Regenerating all four templates reproduces the committed files.
  • Not tested against a live Microsoft account.

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

The changes since the previous review appear safe to merge.

Summary

Adds an OpenAPI generator and replaces OneDrive's hand-written methods with 39 typed operations.

  • Selected API descriptions can now generate typed methods and REST requests.
  • OneDrive now offers typed Graph methods for more drive and file actions.
  • OneDrive users can choose when apps ask before changing files.
  • OneDrive connections now request the permission needed for file changes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["OpenAPI description + operation rules"] --> B["Generate typed methods and request table"]
  B --> C["Check arguments and build request"]
  C --> D{"Does this change need approval?"}
  D -->|Yes| E["Ask the user"]
  E -->|Approved| F["Send with the user's Microsoft token"]
  D -->|No| F
  F --> G["Microsoft Graph"]
  G --> H["Return bounded JSON, content or download URL"]
Loading

Reviews (17) · Last reviewed commit: "Type every OpenAPI success answer, keep ..." · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #320 November 23, 2026 00:09
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 23, 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 0ac8d25 Nov 23 2026, 10:35 AM

Comment thread templates/onedrive/src/api.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch 2 times, most recently from a73d01e to e722349 Compare November 23, 2026 00:35
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from fe1d095 to 9b5389b Compare November 23, 2026 01:16
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from 4106254 to cf77f08 Compare November 23, 2026 01:31
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from cf77f08 to 20ef547 Compare November 23, 2026 01:43
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from 20ef547 to f246533 Compare November 23, 2026 02:01
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from 1f7ada3 to 4655d27 Compare November 23, 2026 10:05
…tion

The OneDrive template offered three hand-written methods: list and search
files and get a download link. It now offers 40 typed methods for OneDrive's
operations of Microsoft Graph: drives, folders and items, search and delta,
content, versions and check-out, sharing and following.

A new OpenAPI generator writes them. Large APIs like Graph describe far more
than one template offers, so a template lists the operations it offers by
operation ID, with method names and the change each non-GET operation makes.
The generator reads JSON or YAML, emits only the types the offered operations
reach, leaves out Graph's navigation properties, and supports Graph's paging
links, file downloads through their temporary address, and text uploads.

Changes ask for approval by each user's level. The connector requests
Files.ReadWrite.All, and accounts connected with fewer permissions are asked
to reconnect.
Like the other templates, OneDrive returns too_large for responses and file
content larger than 8 MiB instead of reading them into memory, and leaves out
optional arguments passed as undefined.
… steps

An operation's parameter replaces the path's parameter of the same name and
place instead of adding a second field. Nullable component types stay
nullable, path parameters are never null, and a required body is checked
before anything is sent. Path values of . or .. are rejected, since they
would move the request to another path.
Required query parameters are checked before sending. An object's other
keys take a type that also fits its named fields, unions keep the null of a
nullable enum when string covers its values, and splitting unions leaves
quoted values whole.
…address

Inputs that would share a name and object query parameters stop generation
instead of producing code that cannot compile or send. A JSON body or result
without a schema takes any JSON. Only the schemas the offered methods reach
need distinct type names, and generated names stay free for the imports and
the service class. Pageable methods accept either their first-page arguments
or only the address of a later page.
…ther keys

Query lists with explode false are joined with the delimiter of their style:
commas for form, spaces and pipes for the delimited styles; other styles stop
generation. A nullable object that only has other keys stays an object type
instead of becoming null.
A path holds one value, so generation stops on path parameters that take a
list or an object instead of offering inputs the runtime would reject.
A nextLink must lead to a page of the same operation: its path with any
parameter values, and for functions such as delta() any arguments, so a link
cannot read other data than the method does. Generated method names are
checked against Widefleet's own app method rule, which also refuses names
such as catch, finally and queue.
@tnkuehne
tnkuehne force-pushed the feat/onedrive-template branch from 4655d27 to 6779fca Compare November 23, 2026 10:16
@tnkuehne
tnkuehne merged commit 2c4542f into main Nov 23, 2026
14 of 15 checks passed
@tnkuehne
tnkuehne deleted the feat/onedrive-template branch November 23, 2026 10:49
tnkuehne added a commit that referenced this pull request Nov 23, 2026
…ription (#326)

## Why

Outlook mail and calendars are the Microsoft counterpart to Gmail and
Google Calendar, and no template covers them yet. The OpenAPI generator
from #322 and the Microsoft login of the OneDrive template cover most of
it. What remains is the list of operations and two things Graph's
description needs.

## What changes

**Outlook template** (`templates/outlook`)

- **Methods:** 68 typed methods for the signed-in user's mailbox.
`scripts/operations.ts` names the Graph operation behind each one.
- **Mail:** messages, MIME content, delta, drafts, send, reply, reply
all and forward (direct and as drafts), move, copy, and attachments.
- **Folders and rules:** mail folders, child folders and their messages,
and inbox rules.
- **Calendar:** calendars, events and calendar views, recurring
instances, meeting responses (accept, tentative, decline, cancel,
forward), reminders, `findMeetingTimes` and `getSchedule`.
- **Contacts and settings:** contacts and contact folders, mailbox
settings, and categories.
- **Approvals:** each user's approval level decides when a method asks.
- **Send:** sending, replying and forwarding mail, creating events
(which invites attendees), and answering, cancelling or forwarding
meetings.
- **Update:** inbox rules, which can forward mail, and mailbox settings,
which include automatic replies.
  - **Create:** drafts, folders, contacts and calendars.
- `findMeetingTimes` and `getSchedule` read through a POST and never
ask.
- **Scopes:** `Mail.ReadWrite`, `Mail.Send`, `Calendars.ReadWrite`,
`Contacts.ReadWrite` and `MailboxSettings.ReadWrite`, from the managed
Microsoft client or the organization's own Entra app. An account
connected with fewer permissions gets `permission_required`.
- **Results and limits:** the same as OneDrive: `graph_error`,
throttling, `too_large` over 8 MiB, and paging through `nextLink`.
- **Icon:** a plain envelope icon, not Microsoft's logo.
- `template.md` describes setup, well-known folder names, OData options,
action bodies, approvals, results and how to offer more operations.

**OpenAPI generator**

- **`read` rule:** rules can mark POST operations that only read, such
as `getSchedule`.
- **`body`/`result` rule:** rules can name the schemas a body or result
can be, where Graph only names their common base. `addAttachment` and
`getAttachment` use file, item and reference attachments, so
`contentBytes` is typed.
- **`navigation` rule:** rules can keep named navigation properties,
typed with their concrete schemas. Outlook's `Message.attachments`
carries file, item and reference attachments inline, for `sendMail` and
drafts.
- **`description` rule:** rules can replace an operation's description.
Graph attaches the text of other operations to some Outlook ones:
`me.ListMessages` says "Get open extension" and `me.CreateEvents` says
"Create multi-value extended property". Seven methods use it.

**Managed OAuth tests**

- Outlook runs through the managed OAuth tests next to OneDrive.

## Managed OAuth

A managed `microsoft` client only grants the scopes its `scopes` setting
allows. Installations that offer managed OAuth for Microsoft must allow
these five scopes, next to OneDrive's `Files.ReadWrite.All` from #322.

## Notes

- **Action bodies:** they use the parameter names of Graph's
description, which are PascalCase, such as `{ Message, SaveToSentItems
}` for `sendMail`. Graph's own SDKs send these names.

## Connection page

New page, connected state, with the same approval form as the other
templates.

| 1280 px | 390 px |
| --- | --- |
| <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/1cc8a17af5f63629af575aa9cfaeeaaffa688e95/outlook-after-1280.png"
width="400"> | <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/1cc8a17af5f63629af575aa9cfaeeaaffa688e95/outlook-after-390.png"
width="200"> |

## Testing

- `pnpm check`
- **Generator:** tests for `read` and `description` rules.
- **Outlook template against a mocked Graph:**
  - typed requests and URLs;
  - paging;
  - MIME content;
  - `getSchedule` never asking;
- drafts running at once, and `sendMail` and deletions asking, then
running after approval;
  - each approval level;
  - missing permissions, with and without the Graph resource prefix;
  - Graph errors, throttling and oversized responses;
  - token refresh, outages and callback checks.
- **Type tests:** the README example compiles; a missing ID and wrong
query types don't.
- **Managed OAuth and catalog tests:** pass with Outlook.
- Not tested against a live Microsoft account.
















<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=116087758&amp;sig=ece23a325ff22d3121927e11de7e8a94e67354b241876b0c7d54f855e71798bb"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F326&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5 <sup><img alt="Tier:
plus" title="Review tier: plus"
src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-plus.svg?v=3"
height="12"></sup></h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no new
actionable issue was established.

<details open><summary><h3>Summary</h3></summary>

Adds 68 typed Outlook methods, Microsoft account connections, approval
controls, and managed OAuth tests. The OpenAPI generator gains rules for
read-only POSTs, concrete body and result types, kept navigation fields,
and descriptions.

- Outlook apps can call typed methods for mail, calendars, contacts, and
settings.
- Outlook asks before methods send messages or make protected changes.
- Each signed-in user can connect and use their own Microsoft account.
- The template generator can describe Outlook’s read-only actions and
concrete attachment types.
- Managed Microsoft OAuth can allow the scopes Outlook needs.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[App calls Outlook method] --> B[Check request arguments]
  B --> C[Check current user's connection]
  C --> D{Change needs approval?}
  D -->|Yes, no answer| E[Ask user]
  E --> A
  D -->|Declined| F[Return declined]
  D -->|Approved or not needed| G[Send request to Microsoft Graph]
  G --> H[Return bounded data or error]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (16) · Last reviewed commit: ["Fit kept navigation fields
into the
type..."](0c01043)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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