Skip to content

Type createApiFetcher() endpoints from OpenAPI schemas - #119

Merged
MattCCC merged 3 commits into
masterfrom
openapi-types
Sep 27, 2026
Merged

MattCCC merged 3 commits into
masterfrom
openapi-types

Conversation

@MattCCC

@MattCCC MattCCC commented Sep 27, 2026

Copy link
Copy Markdown
Owner

This pull request adds OpenApiEndpoint, which types the endpoints of createApiFetcher() from an OpenAPI schema generated by openapi-typescript, so that requests and responses are checked against the schema.

✨ Features & Improvements

  • Added the OpenApiEndpoint<paths, Path, Method> type: it takes the data of the successful (2XX) responses, the request body, the query parameters and the path parameters of an operation from the schema, e.g. getUser: OpenApiEndpoint<paths, '/users/{id}', 'get'>. Responses without content and operations without a request body, query or path parameters are typed as undefined.
  • {param} path placeholders: path parameters can now be written as {id}, like in OpenAPI paths, as well as :id, so the paths of a schema can be used as endpoint URLs as they are. Unknown placeholders are kept as they are.
  • Documented in a new "Typed Endpoints from an OpenAPI Schema" section of Typings.

🧪 Tests

  • Requests and responses typed by a schema like the ones that openapi-typescript generates, including type errors for wrong path params, bodies and response fields (@ts-expect-error), and responses without content.
  • Replacing {param} placeholders, mixed with :param ones, and keeping unknown ones.
  • Coverage stays at 100%.

📦 Bundle Size

The types add nothing to the bundles, and the {param} placeholders add a few bytes. The size limits are raised to fit this and the other pull requests opened alongside it, so that they can be merged in any order.


Generated by Claude Code

OpenApiEndpoint<paths, Path, Method> takes the types of an endpoint from an OpenAPI schema generated by openapi-typescript: the data of its successful responses, its request body, its query parameters and its path parameters. Responses without content and operations without a request body, query or path parameters are typed as undefined. Path parameters can now be written as {id} too, like in OpenAPI paths, so the paths of a schema can be used as endpoint URLs as they are.
Core bundles 7.75 KB -> 8.75 KB, dist/react/index.mjs 10.75 KB -> 11.75 KB and dist/react/index.js 11.75 KB -> 12.75 KB. The limits fit this and the other PRs opened alongside it (abort signal fix, ETag revalidation, retry jitter and methods, onDownloadProgress, responseType, focusThrottleInterval, initialData and typed OpenAPI endpoints), which add about 1 KB together, so that they can be merged in any order.
@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
dist/browser/index.mjs 7.32 KB (+0.07% 🔺)
dist/browser/index.global.js 7.5 KB (+0.15% 🔺)
dist/node/index.js 7.41 KB (+0.2% 🔺)
dist/react/index.mjs 10.34 KB (+0.04% 🔺)
dist/react/index.js 11.23 KB (+0.15% 🔺)

@MattCCC
MattCCC merged commit f979d17 into master Sep 27, 2026
14 checks passed
@MattCCC
MattCCC deleted the openapi-types branch September 27, 2026 20:19
@MattCCC MattCCC mentioned this pull request Sep 27, 2026
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