Generate a React / TypeScript client from an OpenAPI file. Orval is used to generate a client from the tagged OpenAPI file. This is fully typed and provides functions to make API calls along with @tanstack/react-query hooks for queries and mutations. Axios is used to make HTTP calls.
The operationIds can be replaced with more useful names by specifying an x-semantic-name field alongside the operationId. These no longer need to be globally unique (like the operationId does) but still need to be unique within a tag to avoid name clashes.
The source client is built using tsdown. Both CommonJS and ESM outputs are provided. To allow efficient tree-shaking and bundling, each tag from the OpenAPI file is provided in its own submodule as its own entry-point.
To prevent cache collisions when multiple API clients are used in the same application, query keys are automatically prefixed with the API name. This is handled by a post-processing script (morph-query-keys.ts) that runs after code generation. The prefix is extracted from the package name (e.g., @squonk/account-server-client → "account-server").
- The
customInstanceused to make calls is exported for cases where the generated API doesn't provide certain features. - All TypeScript types generated from the OpenAPI spec are exported from here. Import types separately using
import type {} from '@squonk/service-client'.
Each OpenAPI tag is available as a submodule, exporting:
- Query hooks:
use{OperationName}(e.g.,useGetAccountServerNamespace) with prefixed query keys - Suspense query hooks:
use{OperationName}SuspenseQueryfor use with React<Suspense>boundaries - Mutation hooks:
use{OperationName}for POST/PUT/DELETE operations - Query key helpers:
get{OperationName}QueryKey()returns the prefixed query key used by the hook (e.g.,["account-server", "getAccountServerNamespace"]) - Invalidate helpers:
useInvalidate{OperationName}()returns a function to invalidate the query cache
Operation names come from the x-semantic-name fields specified in the OpenAPI spec.