Skip to content

Commit

Permalink
fix(writers): mutators multi arguments correctly generate parameters …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
anymaniax committed Feb 20, 2022
1 parent 7cb7112 commit 6ce1916
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/core/writers/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const generateTarget = (
}

if (index === arr.length - 1) {
const isMutator = acc.mutators.some(
(mutator) => mutator.numberOfParams > (isAngularClient ? 2 : 1),
const isMutator = acc.mutators.some((mutator) =>
isAngularClient ? mutator.hasThirdArg : mutator.hasSecondArg,
);
const header = generateClientHeader({
outputClient: options.client,
Expand Down
4 changes: 2 additions & 2 deletions src/core/writers/targetTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export const generateTargetForTags = (
return Object.entries(targetTags).reduce<
Record<string, GeneratorTargetFull>
>((acc, [tag, target]) => {
const isMutator = !!target.mutators?.some(
(mutator) => mutator.numberOfParams > (isAngularClient ? 2 : 1),
const isMutator = !!target.mutators?.some((mutator) =>
isAngularClient ? mutator.hasThirdArg : mutator.hasSecondArg,
);
const operationNames = Object.values(operations)
.filter(({ tags }) => tags.includes(tag))
Expand Down
25 changes: 25 additions & 0 deletions tests/configs/react-query.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ export default defineConfig({
},
},
},
mutatorMultiArguments: {
output: {
target: '../generated/react-query/mutator-multi-arguments/endpoints.ts',
schemas: '../generated/react-query/mutator-multi-arguments/model',
client: 'react-query',
mock: true,
override: {
mutator: {
path: '../mutators/multi-arguments.ts',
name: 'customInstance',
},
query: {
useQuery: true,
useInfinite: true,
useInfiniteQueryParam: 'limit',
},
},
},
input: {
target: '../specifications/petstore.yaml',
override: {
transformer: '../transformers/add-version.js',
},
},
},
errorType: {
output: {
target: '../generated/react-query/error-type/endpoints.ts',
Expand Down
27 changes: 27 additions & 0 deletions tests/mutators/multi-arguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Axios, { AxiosRequestConfig } from 'axios';

export const AXIOS_INSTANCE = Axios.create({ baseURL: '' });

export const customInstance = <T>(
config: AxiosRequestConfig,
token?: string,
): Promise<T> => {
const source = Axios.CancelToken.source();
const promise = AXIOS_INSTANCE({
...config,
cancelToken: source.token,
headers: {
...config?.headers,
...(token ? { Authorization: token } : {}),
},
}).then(({ data }) => data);

// @ts-ignore
promise.cancel = () => {
source.cancel('Query was cancelled by React Query');
};

return promise;
};

export default customInstance;

0 comments on commit 6ce1916

Please sign in to comment.