Skip to content

Commit 165d458

Browse files
committed
refactor: streamline operation ID generation and clean up utils
This commit includes: - Simplified operation ID generation by removing unnecessary prefixes in client and React Query generators. - Updated the camelCase function in utils to improve readability by removing redundant transformations. - Cleaned up formatting in package.json for consistency.
1 parent 54778c5 commit 165d458

File tree

5 files changed

+5
-9
lines changed

5 files changed

+5
-9
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"license": "MIT",
55
"description": "Generate Axios API clients and React Query options from OpenAPI specifications",
66
"exports": "./dist/index.js",
7-
"files": [
8-
"src",
9-
"dist"
10-
],
7+
"files": ["src", "dist"],
118
"author": {
129
"name": "Oliver Winter",
1310
"email": "owinter86@gmail.com"

src/generator/clientGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function generateApiClient(spec: OpenAPIV3.Document, config: OpenAPIConfi
214214
operations.push({
215215
method: method,
216216
path,
217-
operationId: `${method}_${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
217+
operationId: `${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
218218
summary: operation.summary,
219219
description: operation.description,
220220
parameters: resolveParameters([...(pathItem.parameters || []), ...(operation.parameters || [])]),

src/generator/reactQueryGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document
3636
];
3737

3838
const namedQueryOptions = `get${operationId}QueryOptions`;
39-
const namedQuery = camelCase(`${method}_${operationId}`);
39+
const namedQuery = camelCase(`${operationId}`);
4040

4141
return `
4242
export const ${namedQueryOptions} = (
@@ -66,7 +66,7 @@ export function generateReactQuery(spec: OpenAPIV3.Document): string {
6666
operations.push({
6767
method: method,
6868
path,
69-
operationId: `${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
69+
operationId: `${operation.operationId || `${path.replace(/\W+/g, "_")}`}`,
7070
summary: operation.summary,
7171
description: operation.description,
7272
parameters: [

src/generator/schemaGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function generateTypeDefinitions(spec: OpenAPIV3.Document): string {
106106
const operationObject = operation as OpenAPIV3.OperationObject;
107107
if (!operationObject) continue;
108108
const operationId = pascalCase(
109-
`${method}_${sanitizeTypeName(operationObject.operationId || `${path.replace(/\W+/g, "_")}`)}`
109+
`${sanitizeTypeName(operationObject.operationId || `${path.replace(/\W+/g, "_")}`)}`
110110
);
111111

112112
// Generate request body type

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { OpenAPIV3 } from "openapi-types";
22

33
export function camelCase(str: string): string {
44
return str
5-
.toLowerCase()
65
.replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase())
76
.replace(/^[A-Z]/, (c) => c.toLowerCase());
87
}

0 commit comments

Comments
 (0)