Skip to content

Commit

Permalink
chore(packages): add @summary and @deperecated tags to hook functions (
Browse files Browse the repository at this point in the history
…orval-labs#837)

* chore(packages): add @summary and @deperecated tags to hook functions

* chore(packages): add JSDoc to useMutation
  • Loading branch information
d-mato authored May 23, 2023
1 parent 64070a6 commit 5c1670c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 12 additions & 4 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Verbs,
VERBS_WITH_BODY,
getRouteAsArray,
jsDoc,
} from '@orval/core';
import omitBy from 'lodash.omitby';
import {
Expand Down Expand Up @@ -698,6 +699,7 @@ const generateQueryImplementation = ({
route,
hasVueQueryV4,
hasSvelteQueryV4,
doc,
}: {
queryOption: {
name: string;
Expand All @@ -722,6 +724,7 @@ const generateQueryImplementation = ({
route: string;
hasVueQueryV4: boolean;
hasSvelteQueryV4: boolean;
doc?: string;
}) => {
const queryProps = isVue(outputClient)
? vueWrapTypeWithMaybeRef(toObjectString(props, 'implementation'))
Expand Down Expand Up @@ -866,7 +869,7 @@ export type ${pascal(
)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
export type ${pascal(name)}QueryError = ${errorType}
export const ${camel(
${doc}export const ${camel(
`${operationPrefix}-${name}`,
)} = <TData = Awaited<ReturnType<${dataType}>>, TError = ${errorType}>(\n ${queryProps} ${queryArguments}\n ): ${returnType} => {
Expand Down Expand Up @@ -898,6 +901,8 @@ const generateQueryHook = async (
mutator,
response,
operationId,
summary,
deprecated,
}: GeneratorVerbOptions,
{
route: _route,
Expand All @@ -924,6 +929,8 @@ const generateQueryHook = async (
OutputClient.SVELTE_QUERY === outputClient &&
!isSvelteQueryV3(context.packageJson);

const doc = jsDoc({ summary, deprecated });

if (
verb === Verbs.GET ||
operationQueryOptions?.useInfinite ||
Expand Down Expand Up @@ -1027,6 +1034,7 @@ const generateQueryHook = async (
route,
hasVueQueryV4,
hasSvelteQueryV4,
doc,
}),
'',
)}
Expand Down Expand Up @@ -1183,9 +1191,9 @@ ${mutationOptionsFn}
}
export type ${pascal(operationName)}MutationError = ${errorType}
export const ${camel(
`${operationPrefix}-${operationName}`,
)} = <TError = ${errorType},
${doc}export const ${camel(
`${operationPrefix}-${operationName}`,
)} = <TError = ${errorType},
${!definitions ? `TVariables = void,` : ''}
TContext = unknown>(${mutationArguments}) => {
Expand Down
10 changes: 9 additions & 1 deletion packages/swr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
toObjectString,
Verbs,
VERBS_WITH_BODY,
jsDoc,
} from '@orval/core';

const AXIOS_DEPENDENCIES: GeneratorDependency[] = [
Expand Down Expand Up @@ -197,6 +198,7 @@ const generateSwrImplementation = ({
response,
swrOptions,
props,
doc,
}: {
isRequestOptions: boolean;
operationName: string;
Expand All @@ -208,6 +210,7 @@ const generateSwrImplementation = ({
response: GetterResponse;
mutator?: GeneratorMutator;
swrOptions: { options?: any };
doc?: string;
}) => {
const swrProps = toObjectString(props, 'implementation');
const httpFunctionProps = swrProperties;
Expand All @@ -233,7 +236,7 @@ export type ${pascal(
)}QueryResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
export type ${pascal(operationName)}QueryError = ${errorType}
export const ${camel(
${doc}export const ${camel(
`use-${operationName}`,
)} = <TError = ${errorType}>(\n ${swrProps} ${generateSwrArguments({
operationName,
Expand Down Expand Up @@ -293,6 +296,8 @@ const generateSwrHook = (
override,
mutator,
response,
summary,
deprecated,
}: GeneratorVerbOptions,
{ route }: GeneratorOptions,
) => {
Expand Down Expand Up @@ -321,6 +326,8 @@ const generateSwrHook = (
'implementation',
);

const doc = jsDoc({ summary, deprecated });

return `export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${
queryParams ? ', ...(params ? [params]: [])' : ''
}${body.implementation ? `, ${body.implementation}` : ''}] as const;
Expand All @@ -336,6 +343,7 @@ const generateSwrHook = (
isRequestOptions,
response,
swrOptions: override.swr,
doc,
})}
`;
};
Expand Down

0 comments on commit 5c1670c

Please sign in to comment.