Skip to content

Commit cf3714f

Browse files
authored
Add file names as comments (#1783)
* Add file names as comments Add comments to indicate which file the code snippets should go into. Makes it a bit easier to follow along * move title to code block props
1 parent 4163a76 commit cf3714f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

docs/rtk-query/usage/code-generation.mdx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ We provide a package for RTK Query code generation from OpenAPI schemas. It is p
2828

2929
Create an empty api using `createApi` like
3030

31-
```ts no-transpile
31+
```ts no-transpile title="src/store/emptyApi.ts"
32+
3233
// Or from '@reduxjs/toolkit/query' if not using the auto-generated hooks
3334
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
3435

@@ -41,7 +42,8 @@ export const emptySplitApi = createApi({
4142

4243
Generate a config file (json, js or ts) with contents like
4344

44-
```ts no-transpile
45+
```ts no-transpile title="openapi-config.ts"
46+
4547
import { ConfigFile } from '@rtk-query/codegen-openapi'
4648

4749
const config: ConfigFile = {
@@ -64,7 +66,8 @@ npx @rtk-query/codegen-openapi openapi-config.ts
6466

6567
### Programmatic usage
6668

67-
```ts no-transpile
69+
```ts no-transpile title="src/store/petApi.ts"
70+
6871
import { generateEndpoints } from '@rtk-query/codegen-openapi'
6972

7073
const api = await generateEndpoints({
@@ -107,7 +110,7 @@ export type EndpointMatcherFunction = (
107110
108111
If you only want to include a few endpoints, you can use the `filterEndpoints` config option to filter your endpoints.
109112
110-
```ts no-transpile
113+
```ts no-transpile title="openapi-config.ts"
111114
const filteredConfig: ConfigFile = {
112115
// ...
113116
// should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder
@@ -119,7 +122,7 @@ const filteredConfig: ConfigFile = {
119122

120123
If an endpoint is generated as a mutation instead of a query or the other way round, you can override that:
121124

122-
```ts no-transpile
125+
```ts no-transpile title="openapi-config.ts"
123126
const withOverride: ConfigFile = {
124127
// ...
125128
endpointOverrides: [
@@ -133,7 +136,7 @@ const withOverride: ConfigFile = {
133136

134137
#### Multiple output files
135138

136-
```ts no-transpile
139+
```ts no-transpile title="openapi-config.ts"
137140
const config: ConfigFile = {
138141
schemaFile: 'https://petstore3.swagger.io/api/v3/openapi.json',
139142
apiFile: './src/store/emptyApi.ts',

0 commit comments

Comments
 (0)