From 0778d31b34a5ee1d09c94113c49fc1d5e70cf57f Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 23 Mar 2025 04:30:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixtures/generated/notion-client.ts | 2 +- legacy/packages/openapi-to-ts-client/src/generate.ts | 12 +++++++----- legacy/packages/openapi-to-ts-client/src/utils.ts | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/legacy/packages/openapi-to-ts-client/fixtures/generated/notion-client.ts b/legacy/packages/openapi-to-ts-client/fixtures/generated/notion-client.ts index 03118c90..48267074 100644 --- a/legacy/packages/openapi-to-ts-client/fixtures/generated/notion-client.ts +++ b/legacy/packages/openapi-to-ts-client/fixtures/generated/notion-client.ts @@ -1468,7 +1468,7 @@ export namespace notion { /** * Agentic Notion client. * - * API specification for Notion + * API specification for Notion. */ export class NotionClient extends AIFunctionsProvider { protected readonly ky: KyInstance diff --git a/legacy/packages/openapi-to-ts-client/src/generate.ts b/legacy/packages/openapi-to-ts-client/src/generate.ts index 82979ce2..5b7780c3 100644 --- a/legacy/packages/openapi-to-ts-client/src/generate.ts +++ b/legacy/packages/openapi-to-ts-client/src/generate.ts @@ -16,6 +16,7 @@ import { getAndResolve, getComponentDisplayName, getComponentName, + getDescription, getOperationParamsName, getOperationResponseName, jsonSchemaToZod, @@ -472,10 +473,9 @@ async function main() { ? '`' + path.replaceAll(/{([^}]+)}/g, '${params["$1"]}') + '`' : `'${path}'` - let description = operation.description || operation.summary - if (description && !/[!.?]$/.test(description)) { - description += '.' - } + const description = getDescription( + operation.description || operation.summary + ) const isDescriptionMultiline = description?.includes('\n') const aiClientMethod = ` @@ -604,6 +604,8 @@ import { z } from 'zod'`.trim() .filter(Boolean) .join('\n\n') + const description = getDescription(spec.info?.description) + const output = ( await prettify( [ @@ -611,7 +613,7 @@ import { z } from 'zod'`.trim() ` /** - * Agentic ${name} client.${spec.info?.description ? `\n *\n * ${spec.info.description}` : ''} + * Agentic ${name} client.${description ? `\n *\n * ${description}` : ''} */ export class ${clientName} extends AIFunctionsProvider { protected readonly ky: KyInstance diff --git a/legacy/packages/openapi-to-ts-client/src/utils.ts b/legacy/packages/openapi-to-ts-client/src/utils.ts index f3ce9f76..a9b8b3c5 100644 --- a/legacy/packages/openapi-to-ts-client/src/utils.ts +++ b/legacy/packages/openapi-to-ts-client/src/utils.ts @@ -322,3 +322,11 @@ export function naiveMergeJSONSchemas(...schemas: IJsonSchema[]): IJsonSchema { return result as IJsonSchema } + +export function getDescription(description?: string): string | undefined { + if (description && !/[!.?]$/.test(description)) { + description += '.' + } + + return description +}