Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): remove generic from axios query function generator #284

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const generalJSTypesWithArray = generalJSTypes.reduce<string[]>(
[],
);

export const VERBS_WITH_BODY = [Verbs.POST, Verbs.PUT, Verbs.PATCH, Verbs.DELETE];
export const VERBS_WITH_BODY = [
Verbs.POST,
Verbs.PUT,
Verbs.PATCH,
Verbs.DELETE,
];

export const URL_REGEX = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/;
export const URL_REGEX =
/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/;
9 changes: 5 additions & 4 deletions src/core/generators/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ const generateAxiosImplementation = (
)
: '';

return `const ${operationName} = <TData = ${
response.definition.success || 'unknown'
}>(\n ${toObjectString(props, 'implementation')}\n ${
return `const ${operationName} = ${toObjectString(
props,
'implementation',
)}\n ${
isRequestOptions && isMutatorHasSecondArg
? `options?: SecondParameter<typeof ${mutator.name}>`
: ''
}) => {${bodyForm}
return ${mutator.name}<TData>(
return ${mutator.name}<${response.definition.success || 'unknown'}>(
${mutatorConfig},
${requestOptions});
}
Expand Down
6 changes: 2 additions & 4 deletions src/core/getters/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ export const getParameters = async ({
parameters,
async (acc, p) => {
if (isReference(p)) {
const {
schema: parameter,
imports,
} = await resolveRef<ParameterObject>(p, context);
const { schema: parameter, imports } =
await resolveRef<ParameterObject>(p, context);

if (parameter.in === 'path' || parameter.in === 'query') {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/async-reduce.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const asyncReduce = <
Result extends unknown,
Item extends unknown = unknown
Item extends unknown = unknown,
>(
arr: Item[],
func: (acc: Result, it: Item, index: number, arr: Item[]) => Promise<Result>,
Expand Down
24 changes: 12 additions & 12 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import debug from 'debug'
import debug from 'debug';

const filter = process.env.ORVAL_DEBUG_FILTER
const DEBUG = process.env.DEBUG
const filter = process.env.ORVAL_DEBUG_FILTER;
const DEBUG = process.env.DEBUG;

interface DebuggerOptions {
onlyWhenFocused?: boolean | string
onlyWhenFocused?: boolean | string;
}

export function createDebugger(
ns: string,
options: DebuggerOptions = {}
options: DebuggerOptions = {},
): debug.Debugger['log'] {
const log = debug(ns)
const { onlyWhenFocused } = options
const focus = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : ns
const log = debug(ns);
const { onlyWhenFocused } = options;
const focus = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : ns;
return (msg: string, ...args: any[]) => {
if (filter && !msg.includes(filter)) {
return
return;
}
if (onlyWhenFocused && !DEBUG?.includes(focus)) {
return
return;
}
log(msg, ...args)
}
log(msg, ...args);
};
}