From b5e0224821fff4e8371a836655ae83a89ec08320 Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Sun, 9 Jun 2024 21:00:43 +0100 Subject: [PATCH 1/4] Dont auto organise imports on save --- .vscode/settings.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 064e78fdb..183bc8dab 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,13 @@ { "editor.codeActionsOnSave": { + "source.organizeImports": "never", "source.fixAll.eslint": "explicit" }, + "[typescript]": { + "editor.codeActionsOnSave": { + "source.organizeImports": "never" + } + }, "editor.quickSuggestions": { "strings": true }, From edee4c738c421cd91c2bd68fbc899860604248c6 Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Sun, 9 Jun 2024 21:28:47 +0100 Subject: [PATCH 2/4] Expose a method name builder on the services options to allow the customisation of the client method --- packages/openapi-ts/src/types/config.ts | 4 ++++ packages/openapi-ts/src/utils/write/services.ts | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/openapi-ts/src/types/config.ts b/packages/openapi-ts/src/types/config.ts index 7bb0b5409..fc007769d 100644 --- a/packages/openapi-ts/src/types/config.ts +++ b/packages/openapi-ts/src/types/config.ts @@ -124,6 +124,10 @@ export interface ClientConfig { * @default '{{name}}Service' */ name?: string; + /** + * Customise the method name of methods within the service + */ + methodNameBuilder?: (service: string, operationId: string) => string; /** * Use operation ID to generate operation names? * @default true diff --git a/packages/openapi-ts/src/utils/write/services.ts b/packages/openapi-ts/src/utils/write/services.ts index d0dc92f44..81845687f 100644 --- a/packages/openapi-ts/src/utils/write/services.ts +++ b/packages/openapi-ts/src/utils/write/services.ts @@ -480,7 +480,14 @@ export const processService = ( accessLevel: 'public', comment: toOperationComment(operation), isStatic: config.name === undefined && config.client !== 'angular', - name: operation.name, + name: config.services.methodNameBuilder + ? camelcase( + config.services.methodNameBuilder( + operation.service, + operation.name, + ), + ) + : operation.name, parameters: toOperationParamType(client, operation), returnType: isStandalone ? undefined From c0e777c7bf8b2c6b17929ac8c60fdfd7638e0609 Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Mon, 10 Jun 2024 07:22:35 +0100 Subject: [PATCH 3/4] Leave casing a concern of the methodNameBuilder --- packages/openapi-ts/src/utils/write/services.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/openapi-ts/src/utils/write/services.ts b/packages/openapi-ts/src/utils/write/services.ts index 81845687f..511322347 100644 --- a/packages/openapi-ts/src/utils/write/services.ts +++ b/packages/openapi-ts/src/utils/write/services.ts @@ -481,12 +481,7 @@ export const processService = ( comment: toOperationComment(operation), isStatic: config.name === undefined && config.client !== 'angular', name: config.services.methodNameBuilder - ? camelcase( - config.services.methodNameBuilder( - operation.service, - operation.name, - ), - ) + ? config.services.methodNameBuilder(operation.service, operation.name) : operation.name, parameters: toOperationParamType(client, operation), returnType: isStandalone From e01c61213e266afad5e3b159682b05957aac6534 Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Mon, 10 Jun 2024 07:25:40 +0100 Subject: [PATCH 4/4] Added changeset --- .changeset/wet-snakes-leave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-snakes-leave.md diff --git a/.changeset/wet-snakes-leave.md b/.changeset/wet-snakes-leave.md new file mode 100644 index 000000000..db6586e2e --- /dev/null +++ b/.changeset/wet-snakes-leave.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': minor +--- + +Add support for customising method names