@@ -28,7 +28,8 @@ We provide a package for RTK Query code generation from OpenAPI schemas. It is p
28
28
29
29
Create an empty api using ` createApi ` like
30
30
31
- ``` ts no-transpile
31
+ ``` ts no-transpile title="src/store/emptyApi.ts"
32
+
32
33
// Or from '@reduxjs/toolkit/query' if not using the auto-generated hooks
33
34
import { createApi , fetchBaseQuery } from ' @reduxjs/toolkit/query/react'
34
35
@@ -41,7 +42,8 @@ export const emptySplitApi = createApi({
41
42
42
43
Generate a config file (json, js or ts) with contents like
43
44
44
- ``` ts no-transpile
45
+ ``` ts no-transpile title="openapi-config.ts"
46
+
45
47
import { ConfigFile } from ' @rtk-query/codegen-openapi'
46
48
47
49
const config: ConfigFile = {
@@ -64,7 +66,8 @@ npx @rtk-query/codegen-openapi openapi-config.ts
64
66
65
67
### Programmatic usage
66
68
67
- ``` ts no-transpile
69
+ ``` ts no-transpile title="src/store/petApi.ts"
70
+
68
71
import { generateEndpoints } from ' @rtk-query/codegen-openapi'
69
72
70
73
const api = await generateEndpoints ({
@@ -107,7 +110,7 @@ export type EndpointMatcherFunction = (
107
110
108
111
If you only want to include a few endpoints, you can use the ` filterEndpoints ` config option to filter your endpoints.
109
112
110
- ` ` ` ts no -transpile
113
+ ` ` ` ts no -transpile title = " openapi-config.ts "
111
114
const filteredConfig: ConfigFile = {
112
115
// ...
113
116
// should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder
@@ -119,7 +122,7 @@ const filteredConfig: ConfigFile = {
119
122
120
123
If an endpoint is generated as a mutation instead of a query or the other way round, you can override that:
121
124
122
- ``` ts no-transpile
125
+ ``` ts no-transpile title="openapi-config.ts"
123
126
const withOverride: ConfigFile = {
124
127
// ...
125
128
endpointOverrides: [
@@ -133,7 +136,7 @@ const withOverride: ConfigFile = {
133
136
134
137
#### Multiple output files
135
138
136
- ``` ts no-transpile
139
+ ``` ts no-transpile title="openapi-config.ts"
137
140
const config: ConfigFile = {
138
141
schemaFile: ' https://petstore3.swagger.io/api/v3/openapi.json' ,
139
142
apiFile: ' ./src/store/emptyApi.ts' ,
0 commit comments