Skip to content

Commit a739340

Browse files
Ashniu123claude
andcommitted
refactor: delete five unused functions from naming-utils
Each was an early-generation helper that a later implementation replaced without the original being removed: pathToResourceName -> logic now inlined in openapi-parser.ts operationIdToMethodName -> determineMethodName in api-generator.ts operationIdToTypeName -> operationIdToBaseTypeName extractPathParams -> getFirstPathParamName getResourceGroup -> groupEndpointsByResource getResourceGroup is the one worth calling out: it still carried the naive `endsWith('s') ? slice(0, -1)` singularization that 627f09a fixed in api-generator.ts, so it was a live trap for anyone who wired it up. No cascade -- snakeToCamel and snakeToPascal remain in use from api-generator.ts and type-generator.ts. Scope: scripts/ only. Confirmed by counting references minus declarations for every function in non-generated code (13 exported and 18 module-local in scripts/, 7 local in src/), then closing the gaps that census misses: all 13 exported interfaces in openapi-parser.ts (every one reachable from OpenApiSpec), arrow-function consts (none exist), and every private/protected method in src/ (all used). These five were the only dead ones. Nothing removed from src/. Its exports are published API, so an export with no internal caller is still a consumer's entry point, not dead code -- and the 250+ methods in zoomApi.generated.ts are the library's product. `npm run generate` produces byte-identical output before and after these deletions, which is the strongest available evidence that nothing reachable was removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent af5413d commit a739340

1 file changed

Lines changed: 1 addition & 131 deletions

File tree

scripts/lib/naming-utils.ts

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
* Naming utilities for converting OpenAPI identifiers to TypeScript names.
33
*/
44

5-
/**
6-
* Convert a path to a resource name.
7-
* Examples:
8-
* /users/{userId}/meetings -> users
9-
* /meetings/{meetingId} -> meetings
10-
* /past_meetings/{meetingId} -> pastMeetings
11-
* /tracking_fields -> trackingFields
12-
*/
13-
export function pathToResourceName(path: string): string {
14-
const firstSegment = path.split('/').filter(Boolean)[0];
15-
// Remove path parameters and convert to camelCase
16-
return snakeToCamel(firstSegment.replace(/\{[^}]+\}/g, ''));
17-
}
18-
195
/**
206
* Convert snake_case to camelCase.
217
*/
@@ -31,81 +17,6 @@ export function snakeToPascal(str: string): string {
3117
return camel.charAt(0).toUpperCase() + camel.slice(1);
3218
}
3319

34-
/**
35-
* Convert an operationId to a method name.
36-
* Examples:
37-
* meetings -> list
38-
* meetingCreate -> create
39-
* meeting -> get
40-
* meetingDelete -> delete
41-
* meetingUpdate -> update
42-
* recordingGet -> getRecording
43-
* pastMeetingDetails -> details
44-
* pastMeetingParticipants -> participants
45-
*/
46-
export function operationIdToMethodName(
47-
operationId: string,
48-
httpMethod: string,
49-
): string {
50-
// Common suffix patterns
51-
const suffixMappings: Record<string, string> = {
52-
Create: 'create',
53-
Delete: 'delete',
54-
Update: 'update',
55-
Get: 'get',
56-
List: 'list',
57-
};
58-
59-
// Check for common patterns
60-
for (const [suffix, methodName] of Object.entries(suffixMappings)) {
61-
if (operationId.endsWith(suffix)) {
62-
return methodName;
63-
}
64-
}
65-
66-
// If it's a simple plural name, it's likely a list operation
67-
if (httpMethod === 'get' && operationId.match(/^[a-z]+s$/)) {
68-
return 'list';
69-
}
70-
71-
// If it's a simple singular name, it's likely a get operation
72-
if (httpMethod === 'get' && operationId.match(/^[a-z]+$/)) {
73-
return 'get';
74-
}
75-
76-
// For compound names, extract the meaningful part
77-
// e.g., pastMeetingDetails -> details, pastMeetingParticipants -> participants
78-
const match = operationId.match(/[A-Z][a-z]+$/);
79-
if (match) {
80-
return match[0].toLowerCase();
81-
}
82-
83-
// Default: use the operationId as-is, converted to camelCase
84-
return operationId.charAt(0).toLowerCase() + operationId.slice(1);
85-
}
86-
87-
/**
88-
* Convert an operationId to a TypeScript type name prefix.
89-
* Examples:
90-
* meetings -> Meetings$List
91-
* meetingCreate -> Meetings$Create
92-
* pastMeetingDetails -> PastMeeting$Details
93-
*/
94-
export function operationIdToTypeName(operationId: string): string {
95-
// Convert camelCase to parts
96-
const parts = operationId.split(/(?=[A-Z])/);
97-
98-
// Find resource and operation
99-
// Common patterns: meetings, meetingCreate, pastMeetingDetails
100-
if (parts.length === 1) {
101-
// Simple name like "meetings" -> "Meetings"
102-
return snakeToPascal(parts[0]);
103-
}
104-
105-
// Capitalize each part and join with $
106-
return parts.map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join('$');
107-
}
108-
10920
/**
11021
* Sanitize a string to be a valid TypeScript identifier.
11122
*/
@@ -119,7 +30,7 @@ export function sanitizeIdentifier(str: string): string {
11930

12031
// Ensure it doesn't start with a number
12132
if (/^[0-9]/.test(sanitized)) {
122-
sanitized = '_' + sanitized;
33+
sanitized = `_${sanitized}`;
12334
}
12435

12536
return sanitized || 'unknown';
@@ -133,44 +44,3 @@ export function sanitizeIdentifier(str: string): string {
13344
export function escapeJsDoc(text: string): string {
13445
return text.replace(/\*\//g, '*\\/');
13546
}
136-
137-
/**
138-
* Extract path parameters from a path string.
139-
* Example: /users/{userId}/meetings/{meetingId} -> ['userId', 'meetingId']
140-
*/
141-
export function extractPathParams(path: string): string[] {
142-
const matches = path.match(/\{([^}]+)\}/g);
143-
if (!matches) return [];
144-
return matches.map((m) => m.slice(1, -1));
145-
}
146-
147-
/**
148-
* Determine the resource group for an endpoint based on its path and tags.
149-
*/
150-
export function getResourceGroup(
151-
path: string,
152-
tags: string[],
153-
): { resource: string; isParameterized: boolean; paramName?: string } {
154-
const segments = path.split('/').filter(Boolean);
155-
156-
// Check for parameterized resources like /past_meetings/{id}
157-
if (segments.length >= 2 && segments[1].startsWith('{')) {
158-
const resource = snakeToCamel(segments[0]);
159-
// Convert plural to singular for parameterized access
160-
// past_meetings -> pastMeeting
161-
const singularResource = resource.endsWith('s')
162-
? resource.slice(0, -1)
163-
: resource;
164-
return {
165-
resource: singularResource,
166-
isParameterized: true,
167-
paramName: segments[1].slice(1, -1),
168-
};
169-
}
170-
171-
// Regular resource
172-
return {
173-
resource: snakeToCamel(segments[0]),
174-
isParameterized: false,
175-
};
176-
}

0 commit comments

Comments
 (0)