redux-toolkit
redux-toolkit copied to clipboard
RTK Query Generation: Append some code at the top of the file.
This is my openapi-config.ts
import type { ConfigFile } from '@rtk-query/codegen-openapi';
const config: ConfigFile = {
schemaFile: `http://localhost:3000/api-docs?type=json`,
apiFile: './src/redux/emptyAPI.ts',
apiImport: 'emptySplitApi',
outputFile: './src/redux/myApi.ts',
exportName: 'myApi',
hooks: {
lazyQueries: true,
mutations: true,
queries: true,
},
};
export default config;
and it generates something like this.
import { emptySplitApi as api } from './emptyAPI';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
postApiUserLogout: build.mutation<PostApiUserLogoutApiResponse, PostApiUserLogoutApiArg>({
query: (queryArg) => ({
url: `/api/user/logout`,
method: 'POST',
body: queryArg.body,
headers: { 'Content-Type': queryArg['Content-Type'], Accept: queryArg.accept },
}),
}),
...
There is two issues with this.
- i have to manually add export in line 2 after every generation(i wish there is an option to that automatically)
- There are some typing issues, that i know wouldn't make any issues, but i just want to
@ts-nocheckat the top of the file, is this possible?
You should see something like export { injectedRtkApi as myApi } on the line after that function. No need to add the export keyword on line 2.
@yassinebridi Hello, can you provide your json as well ? I am curious how did you manage to generate endpoint where you can set headers (from what I saw it seems that it does not care about what the api consumes or produces, it is not reflected in the generated file), Thank you