manage-server-data/generate-rtk-query-from-openapi
This skill generates RTK Query endpoints from OpenAPI schemas using the @rtk-query/codegen-openapi library.
Community author
- Agents
- Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode
- License
- MIT (permissive)
- Pin
- 0fd611cpinned Oct 9, 2026
- Context cost
- about 1,200 tokenswhen the skill loads
- GitHub stars
- 11,230on reduxjs/redux-toolkit
- Scripts
- None found
What it does
“Use this when generating RTK Query endpoints from OpenAPI schemas with @rtk-query/codegen-openapi. Covers the empty API pattern, filterEndpoints, endpointOverrides, generated tags, and reviewing generated output before it becomes part of the app.”
Generated summary from the skill's own text
This skill generates RTK Query endpoints from OpenAPI schemas using the @rtk-query/codegen-openapi library. It handles extending an empty shared API, filtering endpoints for broad schemas, and applying overrides to fix generated code before deployment. The agent learns patterns for proper setup, cache invalidation with tags, and review practices to ensure generated code fits application architecture.
When to use it
- Converting OpenAPI specifications into RTK Query client code
- Extending a shared empty API with multiple endpoint groups
- Narrowing broad OpenAPI schemas to specific endpoint subsets
- Customizing generated endpoint types, parameters, or cache tags
When not to
- Building RTK Query APIs from scratch without OpenAPI specs
- Using generated code without review or validation
- Creating separate API roots instead of extending shared architecture
Install
These commands install from the publisher's repository and need no account.
skills CLI
npx skills add reduxjs/redux-toolkit --skill manage-server-data/generate-rtk-query-from-openapiInstalls from the repository's default branch, which may have changed since the commit we checked.
GitHub CLI 2.90 or later
gh skill install reduxjs/redux-toolkit manage-server-data/generate-rtk-query-from-openapi@0fd611cc79d44990ac9a040dec4d5cb446233440Installs the commit we checked (0fd611c).
Copy by hand
Download the folder at 0fd611c and put it in .claude/skills/generate-rtk-query-from-openapi for Claude Code and in .agents/skills/generate-rtk-query-from-openapi for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Copy for your agent
A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.
Prompt
Install the agent skill "manage-server-data/generate-rtk-query-from-openapi" by reduxjs. Source, pinned to commit 0fd611cc79d44990ac9a040dec4d5cb446233440: https://github.com/reduxjs/redux-toolkit/tree/0fd611cc79d44990ac9a040dec4d5cb446233440/packages/rtk-query-codegen-openapi/skills/manage-server-data/generate-rtk-query-from-openapi 1. Download that folder at exactly this commit. Do not use the default branch. 2. Copy every file unchanged, keeping the folder structure, into .claude/skills/generate-rtk-query-from-openapi/ for Claude Code and .agents/skills/generate-rtk-query-from-openapi/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist. 3. Do not edit the files, and do not run any script in the folder unless I ask you to. 4. When you are done, list the files you copied and where you put them. Listing and checks: https://www.agentnative.dev/skills/reduxjs/manage-server-data-generate-rtk-query-from-openapi
SKILL.md at the pin
---
name: manage-server-data/generate-rtk-query-from-openapi
description: >
Use this when generating RTK Query endpoints from OpenAPI schemas with
@rtk-query/codegen-openapi. Covers the empty API pattern, filterEndpoints,
endpointOverrides, generated tags, and reviewing generated output before it
becomes part of the app.
type: composition
library: '@rtk-query/codegen-openapi'
library_version: '2.2.0'
requires:
- manage-server-data/adopt-rtk-query
sources:
- 'reduxjs/redux-toolkit:docs/rtk-query/usage/code-generation.mdx'
- 'reduxjs/redux-toolkit:packages/rtk-query-codegen-openapi/src/types.ts'
- 'reduxjs/redux-toolkit:packages/rtk-query-codegen-openapi/src/generate.ts'
- 'reduxjs/redux-toolkit:packages/rtk-query-codegen-openapi/README.md'
---
# Generate RTK Query From OpenAPI
## Setup
```ts
// file: src/store/emptyApi.ts
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const emptySplitApi = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
endpoints: () => ({}),
});
// file: openapi-config.ts
import type { ConfigFile } from '@rtk-query/codegen-openapi';
const config: ConfigFile = {
schemaFile: 'https://petstore3.swagger.io/api/v3/openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
hooks: true,
};
export default config;
```
Run:
```bash
npx @rtk-query/codegen-openapi openapi-config.ts
```
## Core Patterns
### Generate into an empty shared API
```ts
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const emptySplitApi = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
endpoints: () => ({}),
});
```
Codegen works best when it extends a single RTK Query architecture instead of creating standalone API roots.
### Filter endpoints when the schema is too broad
```ts
import type { ConfigFile } from '@rtk-query/codegen-openapi';
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/userApi.ts',
exportName: 'userApi',
hooks: true,
filterEndpoints: ['loginUser', /User/],
};
export default config;
```
Start with a narrow slice of the schema if the full surface area is too noisy or the package boundaries differ from the OpenAPI file.
### Use `endpointOverrides` to fix generation results
```ts
import type { ConfigFile } from '@rtk-query/codegen-openapi';
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
hooks: true,
tag: true,
endpointOverrides: [
{
pattern: 'loginUser',
type: 'mutation',
},
{
pattern: /.*/,
parameterFilter: (_name, parameter) => parameter.in !== 'header',
},
{
pattern: 'getPetById',
providesTags: ['SinglePet'],
},
],
};
export default config;
```
Review generated endpoints and override type, parameter, or tag behavior instead of hand-editing the emitted file.
## Common Mistakes
### HIGH Assuming generated tags are already specific enough
Wrong:
```ts
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
tag: true,
};
```
Correct:
```ts
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
tag: true,
endpointOverrides: [
{
pattern: 'getPetById',
providesTags: ['SinglePet'],
},
],
};
```
Generated tags are string-only by default, so they can invalidate more cache than intended.
Source: reduxjs/redux-toolkit:docs/rtk-query/usage/code-generation.mdx
### HIGH Generating a brand-new API root instead of extending an empty one
Wrong:
```ts
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
type Pet = { id: string; name: string };
export const petApi = createApi({
reducerPath: 'petApi',
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
endpoints: (build) => ({
getPetById: build.query<Pet, string>({
query: (id) => `pets/${id}`,
}),
}),
});
```
Correct:
```ts
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const emptySplitApi = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
endpoints: () => ({}),
});
```
Generated code should plug into one RTK Query architecture so invalidation and store wiring stay coherent.
Source: reduxjs/redux-toolkit:docs/rtk-query/usage/code-generation.mdx
### MEDIUM Trusting generated shapes without overrides or review
Wrong:
```ts
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
};
```
Correct:
```ts
const config: ConfigFile = {
schemaFile: './openapi.json',
apiFile: './src/store/emptyApi.ts',
apiImport: 'emptySplitApi',
outputFile: './src/store/petApi.ts',
exportName: 'petApi',
endpointOverrides: [
{
pattern: 'loginUser',
type: 'mutation',
},
],
};
```
Real schemas often need type, parameter, or tag correction; treat generated output as reviewed source, not gospel.
Source: reduxjs/redux-toolkit:docs/rtk-query/usage/code-generation.mdx
## References
- [Codegen override patterns and review checklist](references/codegen-overrides.md)
From reduxjs/redux-toolkit at 0fd611c, shown as plain text under its license: MIT (permissive). The license text is in LICENSE.
View SKILL.md on GitHub at 0fd611cFiles
- SKILL.md5.8 KB · 9ab7aaa9c6cf
- references/
- codegen-overrides.md1.3 KB · c7ad354c89a1
2 files, 7.1 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at 0fd611cRelated in Frontend and design
next-bundle-optimizer
Audits Next.js applications to identify and reduce browser bundle size and initial-load work by analyzing routes, dependencies and client outputs.
by VercelOfficial publisher
Claude Code, Codex, Cursor +4 · about 2.3K tokens · pinned 6 days ago
next-cache-components-optimizer
Optimize Next.js routes to display meaningful UI instantly on initial load or client navigation by encoding the optimization goal as a failing…
by VercelOfficial publisher
Claude Code, Codex, Cursor +4 · about 5.6K tokens · pinned 6 days ago
next-partial-prefetching-adoption
Enables Partial Prefetching in Next.js 16.3+ apps and guides adoption through auditing Link prefetch behavior, preserving UI in tests or manually, and…
by VercelOfficial publisher
Claude Code, Codex, Cursor +4 · about 6.7K tokens · pinned 6 days ago
remotion-interactivity
This skill teaches how to structure Remotion code so the Studio IDE recognizes and makes it interactive.
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 2.4K tokens · pinned 6 days ago
remotion-interactivity
This skill teaches how to structure Remotion video components to unlock Studio interactivity features like click selection, drag-and-drop, resizing, rotation…
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 4.8K tokens · pinned 6 days ago
remotion-maps
This skill enables creating map-based animations with Remotion using four different mapping libraries: Mapbox, MapLibre, MapTiler, or CesiumJS.
by RemotionOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 240 tokens · pinned 6 days ago