Skip to content

Add a Strava template generated from Strava's Swagger description - #343

Merged
tnkuehne merged 6 commits into
mainfrom
feat/strava-template
Nov 23, 2026
Merged

tnkuehne merged 6 commits into
mainfrom
feat/strava-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Change

The OpenAPI generator reads Swagger 2.0 descriptions with sibling files. Strava publishes its API as Swagger 2.0, with its schemas in separate files.

  • It brings the schemas of referenced files into the description and resolves references inside each file against that file. Two schemas with the same name stop the generator.
  • It converts Swagger 2.0 to the OpenAPI 3 form it already reads: server, parameters, list formats, JSON, form and multipart bodies, and file responses.
  • The generator's source stays Strava's published URL. With a local source file, referenced files are read next to it.

Generator and REST runtime.

  • Form and multipart bodies, with files as UploadContent.
  • 64-bit integer IDs also accept strings, since they may exceed what a JSON number holds exactly.
  • The generator stops on a path parameter that has no place in its path, and on a path placeholder that no parameter fills.
  • Form lists keep their collectionFormat and are joined into one value; tsv and the other delimited formats join in the generator and the runtime.
  • References to whole files and back to the root document resolve.
  • New rules: parameters adds a parameter the description leaves out, and fields replaces a body field. Strava uses them for listRoutes' athlete ID and for the keyed tags[…] fields of createActivity and createUpload.
  • OneDrive and Outlook pick up the shared runtime. Their api.ts is unchanged.

A Strava template.

  • 30 methods for the connected athlete's data:
    • profile, zones and stats
    • activities with laps, zones, comments and kudos
    • streams, clubs and gear
    • routes with GPX and TCX exports
    • segments, segment efforts and uploads
  • Each organization connects through its own Strava API application, with STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET. There is no managed client.
  • Better Auth has no Strava provider, so the template uses its generic OAuth plugin. Strava's token answer names no scopes, so the scopes the athlete granted are taken from the callback.
  • Approvals:
    • Creating and uploading activities, which followers see, asks as send.
    • Updating activities and starring segments asks as update.
  • template.md points to Strava's API Agreement and Policy. It also covers the single-athlete capacity of new applications and Strava's default rate limits.

Tests

  • Generator tests for Swagger 2.0, sibling files, form and multipart bodies, large IDs and path parameters.
  • Strava template tests: connection with the organization's client, reads, writes with approval, uploads and type checks.
  • Ran pnpm check, the generator tests, and the Strava, OneDrive and Outlook template tests.
  • Not yet run against Strava's live API.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issue remains from the reviewed changes.

Summary

Adds a Strava template and Swagger 2.0 support to the generator.

  • The generator reads Swagger descriptions and gathers schemas from sibling files.
  • REST methods send form and multipart bodies and accept large IDs as strings.
  • Strava users can connect their account and use 30 typed API methods.

Review used code inspection. No tests or live Strava calls were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Published description] --> B[Bundle sibling schemas]
  B --> C[Convert Swagger to OpenAPI]
  C --> D[Generate typed methods]
  D --> E[Check user connection]
  E --> F{Change needs approval?}
  F -->|Yes| G[Ask user]
  G -->|Approved| H[Call Strava]
  F -->|No| H
Loading

Reviews (6) · Last reviewed commit: "Check only the form body the generator s..." · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #345 November 23, 2026 14:28
@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 672b1ab Nov 23 2026, 03:41 PM

Comment thread templates/strava/src/schema.ts Resolved
Comment thread templates/strava/src/api.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/strava-template branch from 934c09c to 34cecf6 Compare November 23, 2026 15:03
@tnkuehne
tnkuehne removed this pull request from stack #345 November 23, 2026 15:06
Strava publishes its API as Swagger 2.0, with its schemas in sibling files.
The OpenAPI generator now reads such descriptions: it brings the schemas of
referenced files into the description, resolving references inside each file
against that file, and upgrades Swagger 2.0 to the OpenAPI 3 shape it already
reads. The generator's source stays Strava's published URL; with a source
file, referenced files are read next to it.

The generator and the REST runtime also gain form and multipart bodies, with
files as UploadContent, accept 64-bit integer IDs as strings, since they may
exceed what a JSON number holds, and stop on path parameters the path has no
place for. OneDrive and Outlook pick up the shared runtime.

The Strava template offers 30 methods for the connected athlete's profile,
zones and stats, activities with laps, zones, comments and kudos, streams,
clubs, gear, routes with GPX and TCX exports, segments, segment efforts and
uploads. Each organization connects through its own Strava API application.
Better Auth has no Strava provider, so the template uses its generic OAuth
plugin; Strava's token answer names no scopes, so the scopes the athlete
granted are taken from the callback. Creating and uploading activities, which
followers see, asks as sending; updating activities and starring segments
asks as updates.
Cover the flow Widefleet's My connections page uses: the single-use launch
link, the OAuth callback, the completion link back to Widefleet, expired
links, links opened by another user or twice, and a cancelled authorization
returning with the error.
…enerator

- Every place in an offered path needs a path parameter to fill it; the
  generator stops otherwise. Strava's description leaves out the athlete ID of
  /athletes/{id}/routes, so listRoutes takes it through a new `parameters`
  rule. A `fields` rule replaces, adds or removes form body fields.
- Multipart bodies write out the named schemas that carry files, so their
  binary fields stay uploads; the named types keep strings for answers.
- Form lists keep their format: the Swagger upgrade writes it as the field's
  encoding, and the runtime joins those lists into one value.
- Tab-separated lists join with a tab, and the delimited styles join unless
  `explode` is true, as OpenAPI 3 defaults them.
- References back into the description keep its own schemas, and a file that
  is one schema takes its name from the file.
…ribes

Strava's API reference describes tags as form fields keyed by the tag's name,
such as tags[WithPet]=true, while its description lists one `tags` string.
createActivity and createUpload now take a boolean field for each supported
tag in place of `tags`, through the `fields` rule.
@tnkuehne
tnkuehne force-pushed the feat/strava-template branch from 34cecf6 to 2d8908e Compare November 23, 2026 15:15
Comment thread packages/template-generator/src/cli.ts Resolved
…rt from references

- Multipart forms send object fields, and each object of a list, as JSON
  parts, OpenAPI's default encoding for them. Plain forms have no encoding
  for objects, so the generator stops on object fields there.
- With a local source file, referred files are found at their decoded path
  relative to the source's URL, so `Pet%20Details.json` is `Pet Details.json`
  and `../shared/x.json` lies beside the source's folder.
- References inside literal data, such as examples, defaults, enums,
  constants and `x-` extensions, stay data: bundling neither loads nor
  rewrites them, and neither does the Swagger upgrade.
An operation that offers JSON and a form sends JSON, but the generator also
checked the unused form: an object field, an unsupported list encoding or a
`fields` rule on it stopped generation. The form's fields, encoding and the
`fields` rule now apply only when that form is the body that is sent, and a
`fields` rule without such a form stops with a clear error.
@tnkuehne
tnkuehne merged commit a14ae90 into main Nov 23, 2026
14 of 17 checks passed
@tnkuehne
tnkuehne deleted the feat/strava-template branch November 23, 2026 16:25
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