Skip to content

Conversation

Anmol1696
Copy link
Contributor

@Anmol1696 Anmol1696 commented Sep 12, 2025

Get a registry of sorts setup for the clients and operations

Closes: #11
Closes: #9

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds GVK (Group/Version/Kind) to Kubernetes client binding functionality by introducing a registry system that maps Kubernetes resources to their generated client methods and types.

  • Adds opsIndex configuration option to enable GVK-based operations registry
  • Implements qualified type naming strategy to handle resource name conflicts
  • Generates ResourceTypeMap and utility types for type-safe GVK operations

Reviewed Changes

Copilot reviewed 3 out of 11 changed files in this pull request and generated 7 comments.

File Description
packages/schema-sdk/src/types.ts Adds opsIndex configuration options for GVK registry generation
packages/schema-sdk/src/openapi.ts Implements GVK-based type naming, interface renaming, and registry generation logic
packages/schema-sdk/tests/openapi.extended.generate.test.ts Adds test cases for GVK functionality and qualified naming strategy

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

options: OpenAPIOptions
): string => {
const { group, version, kind } = gvk;

Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extra blank line should be removed for consistent formatting.

Suggested change

Copilot uses AI. Check for mistakes.

options: OpenAPIOptions
): string => {
const { group, version, kind } = gvk;

Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extra blank line should be removed for consistent formatting.

Suggested change

Copilot uses AI. Check for mistakes.

const groupParts = group.split('.').map(part => toPascalCase(part)).join('');
const versionPart = toPascalCase(version);
const qualifiedName = `${groupParts}${versionPart}${toPascalCase(kind)}`;

Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extra blank line should be removed for consistent formatting.

Suggested change

Copilot uses AI. Check for mistakes.

Comment on lines 645 to 646
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined and handle the undefined case explicitly.

Suggested change
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
const operation = (pathItem as any)[m] as Operation | undefined;

Copilot uses AI. Check for mistakes.

Comment on lines 957 to 958
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined and handle the undefined case explicitly.

Suggested change
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
// Use proper type assertion instead of @ts-ignore
const operation = (pathItem as any)[m] as Operation | undefined;

Copilot uses AI. Check for mistakes.

Comment on lines 698 to 699
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined and handle the undefined case explicitly.

Suggested change
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
const operation = (pathItem as any)[m] as Operation | undefined;

Copilot uses AI. Check for mistakes.

Comment on lines 680 to 681
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined and handle the undefined case explicitly.

Suggested change
// @ts-ignore
const operation: Operation = (pathItem as any)[m];
const operation = (pathItem as any)[m] as Operation | undefined;

Copilot uses AI. Check for mistakes.

@Anmol1696 Anmol1696 requested a review from Copilot September 24, 2025 17:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 12 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

) => {
// @ts-ignore
const operation: Operation = pathItem[method];
const operation: Operation | undefined = pathItem[method];
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type assertion is incorrect. pathItem[method] should be cast as pathItem[method as keyof OpenAPIPathItem] as Operation | undefined to properly access the method property on the pathItem object.

Suggested change
const operation: Operation | undefined = pathItem[method];
const operation: Operation | undefined = pathItem[method as keyof OpenAPIPathItem] as Operation | undefined;

Copilot uses AI. Check for mistakes.

// @ts-ignore
const operation: Operation = pathItem[method];
if (!shouldIncludeOperation(options, pathItem, path, method as any))
const operation: Operation | undefined = pathItem[method as keyof OpenAPIPathItem] as Operation | undefined;
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This type assertion pattern is repeated multiple times throughout the file. Consider extracting this into a helper function like getOperationFromPathItem(pathItem: OpenAPIPathItem, method: string): Operation | undefined to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

const { group, version, kind } = gvk;

// Handle core group (empty group) and normalize group names
const groupName = group === '' ? 'Core' : toPascalCase(group.replace(/\./g, ''));
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic string 'Core' is hardcoded here but should use the configurable emptyGroupLabel from options. This creates inconsistency with the configurable label used elsewhere in the code.

Suggested change
const groupName = group === '' ? 'Core' : toPascalCase(group.replace(/\./g, ''));
const groupName = group === '' ? (options.emptyGroupLabel || 'Core') : toPascalCase(group.replace(/\./g, ''));

Copilot uses AI. Check for mistakes.

gvk: { group: string; version: string; kind: string };
scope: 'Namespaced' | 'Cluster' | 'Unknown';
types: { main: string; list?: string };
ops: any; // OperationSpec-ish
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type defeats the purpose of TypeScript's type safety. Define a proper interface for the operations specification or use a more specific type like Record<string, unknown> if the structure is truly variable.

Suggested change
ops: any; // OperationSpec-ish
ops: Record<string, unknown>; // OperationSpec-ish

Copilot uses AI. Check for mistakes.

Comment on lines 1095 to 1108
code = code.replace(
/export type KubernetesResource = ([^;]+);/,
(full, types) => {
const parts = types
.split('|')
.map((part: string) => part.trim())
.filter(Boolean);
if (parts.length <= 1) {
return full;
}
const union = parts.map((part: string) => ` | ${part}`).join('\n');
return `export type KubernetesResource =\n${union};`;
}
);
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using regex string replacement on generated code is fragile and error-prone. Consider generating the union type directly in the AST generation phase instead of post-processing the string output.

Suggested change
code = code.replace(
/export type KubernetesResource = ([^;]+);/,
(full, types) => {
const parts = types
.split('|')
.map((part: string) => part.trim())
.filter(Boolean);
if (parts.length <= 1) {
return full;
}
const union = parts.map((part: string) => ` | ${part}`).join('\n');
return `export type KubernetesResource =\n${union};`;
}
);
// The KubernetesResource union type should be generated in multi-line format directly in the AST phase.

Copilot uses AI. Check for mistakes.

@Anmol1696 Anmol1696 merged commit 5e662c7 into main Sep 24, 2025
1 check passed
@Anmol1696 Anmol1696 deleted the anmol/bind-gkv branch September 24, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: add a KubernetesResource type feature: better namespacing for types and functions
1 participant