Skip to content

Commit

Permalink
docs: endpointOverrides parameter filter explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebws committed Mar 28, 2024
1 parent ca131c3 commit afd882a
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion docs/rtk-query/usage/code-generation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ npx @rtk-query/codegen-openapi openapi-config.ts

#### Generating tags

If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
If your OpenAPI specification uses [tags](https://swagger.io/docs/specification/grouping-operations-with-tags/), you can specify the `tag` option to the codegen.
That will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition.

Note that this will only result in string tags with no ids, so it might lead to scenarios where too much is invalidated and unneccessary requests are made on mutation.
Expand Down Expand Up @@ -144,6 +144,34 @@ const withOverride: ConfigFile = {
}
```

You can also filter the parameters that are included for an endpoint, as long as they aren't a path parameter. This filter is of type `ParameterMatcher`. For example, to only include parameters that begin with "x-" for the 'loginUser' endpoint, see the below example.

```ts no-transpile title="openapi-config.ts"
const withOverride: ConfigFile = {
// ...
endpointOverrides: [
{
pattern: 'loginUser',
parameterFilter: /^x-/,
},
],
}
```

For more complex requirements, consider the other possible matchers, such as a `ParameterMatcherFunction`. The below example filters out any parameters that are in the header of the request.

```ts no-transpile title="openapi-config.ts"
const withOverride: ConfigFile = {
// ...
endpointOverrides: [
{
pattern: /.*/,
parameterFilter: (_name, parameter) => parameter.in !== "header",
},
],
}
```

#### Generating hooks

Setting `hooks: true` will generate `useQuery` and `useMutation` hook exports. If you also want `useLazyQuery` hooks generated or more granular control, you can also pass an object in the shape of: `{ queries: boolean; lazyQueries: boolean; mutations: boolean }`.
Expand Down

0 comments on commit afd882a

Please sign in to comment.