Skip to content

Commit 934dc35

Browse files
committed
API fixes
1 parent b2111d8 commit 934dc35

File tree

5 files changed

+412
-399
lines changed

5 files changed

+412
-399
lines changed

__fixtures__/output/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function KubernetesProvider({
7575
}
7676

7777
// Hook to use Kubernetes context
78-
export function useKubernetes() {
78+
export function useKubernetes(): KubernetesContextValue {
7979
const context = useContext(KubernetesContext)
8080
if (!context) {
8181
throw new Error('useKubernetes must be used within a KubernetesProvider')

__fixtures__/output/hooks.ts

Lines changed: 394 additions & 394 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('generateReactQueryHooks', () => {
2828
enabled: true,
2929
path: 'hooks',
3030
typesImportPath: './swagger-client',
31-
contextImportPath: './k8s-context',
31+
contextImportPath: './context',
3232
},
3333
} as any;
3434
// const testSchema = getFilteredSchema(schema as any, patterns);

packages/schema-sdk/src/context-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ${Type}Provider({
7575
}
7676
7777
// Hook to use ${Type} context
78-
export function use${Type}() {
78+
export function use${Type}(): ${Type}ContextValue {
7979
const context = useContext(${Type}Context)
8080
if (!context) {
8181
throw new Error('use${Type} must be used within a ${Type}Provider')

packages/schema-sdk/src/openapi.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ export function collectReactQueryHookComponents(
701701
);
702702
}
703703
// Import request type only for create (POST) and update (PUT) operations
704-
if (method === 'post' || method === 'put') {
704+
if (method === 'post' || method === 'put' || method === 'patch') {
705705
importDecls.push(
706706
t.importDeclaration(
707707
[t.importSpecifier(t.identifier(requestTypeName), t.identifier(requestTypeName))],
@@ -721,8 +721,21 @@ export function collectReactQueryHookComponents(
721721
], t.stringLiteral('@tanstack/react-query'))
722722
);
723723

724+
// Import request type for GET hook parameter
725+
importDecls.push(
726+
t.importDeclaration(
727+
[t.importSpecifier(t.identifier(requestTypeName), t.identifier(requestTypeName))],
728+
t.stringLiteral(options.hooks.typesImportPath)
729+
)
730+
);
731+
724732
const paramName = 'params';
725-
const funcParams = [t.identifier(paramName)];
733+
// Create a typed parameter identifier for request params
734+
const paramId = t.identifier(paramName);
735+
paramId.typeAnnotation = t.tsTypeAnnotation(
736+
t.tsTypeReference(t.identifier(requestTypeName))
737+
);
738+
const funcParams = [paramId];
726739

727740
statements.push(
728741
t.variableDeclaration('const', [

0 commit comments

Comments
 (0)