From d3e2af6cf52c756d2fde73eb4c02b071177c2c53 Mon Sep 17 00:00:00 2001 From: Alex Vukadinov Date: Wed, 14 May 2025 15:21:58 +0100 Subject: [PATCH 1/4] fix: operationToId should convert case based on config --- packages/openapi-ts/src/openApi/shared/utils/operation.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts index e385345c2..f7296ef05 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/operation.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -61,13 +61,14 @@ export const operationToId = ({ }): string => { let result: string; + const targetCase = context.config.output.case ?? 'camelCase'; if ( id && (!context.config.plugins['@hey-api/sdk'] || context.config.plugins['@hey-api/sdk'].operationId) ) { result = stringCase({ - case: 'camelCase', + case: targetCase, value: sanitizeNamespaceIdentifier(id), }); } else { @@ -77,7 +78,7 @@ export const operationToId = ({ .replace(/[/:+]/g, '-'); result = stringCase({ - case: 'camelCase', + case: targetCase, value: `${method}-${urlWithoutPlaceholders}`, }); } From edc8e2edcfe1e8edbf621854a1a7d3fe3f97442e Mon Sep 17 00:00:00 2001 From: Alex Vukadinov Date: Wed, 14 May 2025 15:31:56 +0100 Subject: [PATCH 2/4] fix: stricter checks on output object before accessing case --- packages/openapi-ts/src/openApi/shared/utils/operation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts index f7296ef05..7cab7bfd4 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/operation.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -61,7 +61,9 @@ export const operationToId = ({ }): string => { let result: string; - const targetCase = context.config.output.case ?? 'camelCase'; + const { output } = context.config; + const targetCase = (output !== void 0 && 'case' in output ? output.case : void 0) ?? 'camelCase'; + if ( id && (!context.config.plugins['@hey-api/sdk'] || From a8d58a45c6a79441bd29fbf8162942e87d54cea4 Mon Sep 17 00:00:00 2001 From: Alex Vukadinov Date: Wed, 14 May 2025 15:37:01 +0100 Subject: [PATCH 3/4] style: format operation.ts with Prettier --- .../src/openApi/shared/utils/operation.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts index 7cab7bfd4..b718740a7 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/operation.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -1,7 +1,7 @@ -import type { IR } from '../../../ir/types'; -import { stringCase } from '../../../utils/stringCase'; -import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize'; -import type { State } from '../types/state'; +import type { IR } from "../../../ir/types"; +import { stringCase } from "../../../utils/stringCase"; +import { sanitizeNamespaceIdentifier } from "../../common/parser/sanitize"; +import type { State } from "../types/state"; /** * Verifies that operation ID is unique. For now, we only warn when this isn't @@ -17,7 +17,7 @@ export const ensureUniqueOperationId = ({ }: { context: IR.Context; id: string | undefined; - method: IR.OperationObject['method']; + method: IR.OperationObject["method"]; operationIds: Map; path: keyof IR.PathsObject; }) => { @@ -28,10 +28,10 @@ export const ensureUniqueOperationId = ({ const operationKey = `${method.toUpperCase()} ${path}`; if (operationIds.has(id)) { - if (context.config.logs.level !== 'silent') { + if (context.config.logs.level !== "silent") { // TODO: parser - support throw on duplicate console.warn( - `❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`, + `❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.` ); } } else { @@ -57,17 +57,19 @@ export const operationToId = ({ id: string | undefined; method: string; path: string; - state: Pick; + state: Pick; }): string => { let result: string; const { output } = context.config; - const targetCase = (output !== void 0 && 'case' in output ? output.case : void 0) ?? 'camelCase'; + const targetCase = + (output !== void 0 && "case" in output ? output.case : void 0) ?? + "camelCase"; if ( id && - (!context.config.plugins['@hey-api/sdk'] || - context.config.plugins['@hey-api/sdk'].operationId) + (!context.config.plugins["@hey-api/sdk"] || + context.config.plugins["@hey-api/sdk"].operationId) ) { result = stringCase({ case: targetCase, @@ -75,9 +77,9 @@ export const operationToId = ({ }); } else { const urlWithoutPlaceholders = path - .replace(/{(.*?)}/g, 'by-$1') + .replace(/{(.*?)}/g, "by-$1") // replace slashes with hyphens for camelcase method at the end - .replace(/[/:+]/g, '-'); + .replace(/[/:+]/g, "-"); result = stringCase({ case: targetCase, From d6db4122c2d2c77a3bb7b8e813c2b793ec71c5a9 Mon Sep 17 00:00:00 2001 From: Alex Vukadinov Date: Wed, 14 May 2025 17:56:47 +0300 Subject: [PATCH 4/4] style: fix prettier warning in operation.ts --- .../src/openApi/shared/utils/operation.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts index b718740a7..551334765 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/operation.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -1,7 +1,7 @@ -import type { IR } from "../../../ir/types"; -import { stringCase } from "../../../utils/stringCase"; -import { sanitizeNamespaceIdentifier } from "../../common/parser/sanitize"; -import type { State } from "../types/state"; +import type { IR } from '../../../ir/types'; +import { stringCase } from '../../../utils/stringCase'; +import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize'; +import type { State } from '../types/state'; /** * Verifies that operation ID is unique. For now, we only warn when this isn't @@ -17,7 +17,7 @@ export const ensureUniqueOperationId = ({ }: { context: IR.Context; id: string | undefined; - method: IR.OperationObject["method"]; + method: IR.OperationObject['method']; operationIds: Map; path: keyof IR.PathsObject; }) => { @@ -28,10 +28,10 @@ export const ensureUniqueOperationId = ({ const operationKey = `${method.toUpperCase()} ${path}`; if (operationIds.has(id)) { - if (context.config.logs.level !== "silent") { + if (context.config.logs.level !== 'silent') { // TODO: parser - support throw on duplicate console.warn( - `❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.` + `❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`, ); } } else { @@ -57,19 +57,19 @@ export const operationToId = ({ id: string | undefined; method: string; path: string; - state: Pick; + state: Pick; }): string => { let result: string; const { output } = context.config; const targetCase = - (output !== void 0 && "case" in output ? output.case : void 0) ?? - "camelCase"; + (output !== void 0 && 'case' in output ? output.case : void 0) ?? + 'camelCase'; if ( id && - (!context.config.plugins["@hey-api/sdk"] || - context.config.plugins["@hey-api/sdk"].operationId) + (!context.config.plugins['@hey-api/sdk'] || + context.config.plugins['@hey-api/sdk'].operationId) ) { result = stringCase({ case: targetCase, @@ -77,9 +77,9 @@ export const operationToId = ({ }); } else { const urlWithoutPlaceholders = path - .replace(/{(.*?)}/g, "by-$1") + .replace(/{(.*?)}/g, 'by-$1') // replace slashes with hyphens for camelcase method at the end - .replace(/[/:+]/g, "-"); + .replace(/[/:+]/g, '-'); result = stringCase({ case: targetCase,