Skip to content

Commit d07563d

Browse files
committed
hooks
1 parent 85eca17 commit d07563d

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

packages/schema-sdk/__tests__/hooks.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ describe('generateReactQueryHooks', () => {
3535
const hooks = generateReactQueryHooks(options, testSchema);
3636
expect(hooks.length).toBeGreaterThan(0);
3737
// Verify each hook file has expected properties
38-
hooks.forEach(hook => {
39-
expect(hook).toHaveProperty('fileName');
40-
expect(hook).toHaveProperty('code');
41-
});
38+
expect(hooks).toHaveProperty('fileName');
39+
expect(hooks).toHaveProperty('code');
4240

4341
writeFileSync(
4442
__dirname + '/../../../__fixtures__/output/hooks.ts',
45-
hooks[0].code
43+
hooks
4644
);
4745
});
4846
});

packages/schema-sdk/src/openapi.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,6 @@ export function generateMethods(
525525

526526
METHOD_TYPES.forEach((method) => {
527527
// Hoist file path and key declaration for this hook
528-
const normalized = normalizePath(path);
529-
const fileName = `${options.hooks?.path ?? 'hooks'}/${normalized}_${method}.ts`;
530-
const keyName = `${normalized.toUpperCase()}_KEY`;
531-
const keyDecl = t.variableDeclaration('const', [
532-
t.variableDeclarator(
533-
t.identifier(keyName),
534-
t.arrayExpression([t.stringLiteral(normalized)])
535-
),
536-
]);
537528
const operation = (pathItem as any)[method] as Operation;
538529
if (!operation || !shouldIncludeOperation(options, pathItem, path, method as any)) {
539530
return;
@@ -660,7 +651,6 @@ export interface HookComponent {
660651
importDecls: t.ImportDeclaration[];
661652
funcDecl: t.ExportNamedDeclaration;
662653
constDecls: t.VariableDeclaration[];
663-
fileName: string;
664654
}
665655

666656
/**
@@ -805,7 +795,7 @@ export function collectReactQueryHookComponents(
805795
[]
806796
);
807797

808-
components.push({ importDecls, funcDecl, constDecls: [keyDecl], fileName: `${options.hooks.path}/${hookName}.ts` });
798+
components.push({ importDecls, funcDecl, constDecls: [keyDecl] });
809799
} else {
810800
importDecls.push(
811801
t.importDeclaration([
@@ -891,7 +881,7 @@ export function collectReactQueryHookComponents(
891881
[]
892882
);
893883

894-
components.push({ importDecls, funcDecl, constDecls: [keyDecl], fileName: `${options.hooks.path}/${hookName}.ts` });
884+
components.push({ importDecls, funcDecl, constDecls: [keyDecl] });
895885
}
896886
});
897887
});
@@ -905,10 +895,9 @@ export function collectReactQueryHookComponents(
905895
export function generateReactQueryHooks(
906896
options: OpenAPIOptions,
907897
schema: OpenAPISpec
908-
): HookFile[] {
898+
): string {
909899
const components = collectReactQueryHookComponents(options, schema);
910-
if (!components.length) return [];
911-
const basePath = options.hooks?.path ?? 'hooks';
900+
if (!components.length) return ''
912901
// Group imports
913902
const importMap = new Map<string, Set<string>>();
914903
// Collect unique imports and consts
@@ -946,7 +935,7 @@ export function generateReactQueryHooks(
946935
// Build AST and generate code
947936
const ast = t.file(t.program([...uniqueImportDecls, ...uniqueConstDecls, ...funcDecls]));
948937
const code = generate(ast).code;
949-
return [{ fileName: `${basePath}/index.ts`, code }];
938+
return code;
950939
}
951940

952941
/**

packages/schema-sdk/src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface OpenAPIOptions extends SchemaTSOptions {
3030
};
3131
hooks?: {
3232
enabled?: boolean;
33-
path?: string;
3433
/**
3534
* Custom hook name for context, e.g. useKubernetes
3635
*/
@@ -64,7 +63,6 @@ export const defaultSchemaSDKOptions: DeepPartial<OpenAPIOptions> = {
6463
},
6564
hooks: {
6665
enabled: false,
67-
path: 'hooks',
6866
typesImportPath: './client',
6967
contextHookName: './context'
7068
},

0 commit comments

Comments
 (0)