From d579559cb10533f6498d6c126aa59476a9599888 Mon Sep 17 00:00:00 2001 From: Ryo Date: Wed, 8 Apr 2026 09:53:17 +0800 Subject: [PATCH] fix: openapi schema issue while creating openapi json (#6727) --- packages/global/core/chat/helperBot/type.ts | 2 +- .../global/openapi/core/ai/sandbox/api.ts | 2 +- .../global/openapi/core/app/common/api.ts | 18 ++++++++++++++++- .../global/openapi/core/chat/helperBot/api.ts | 10 ++++------ .../openapi/support/user/account/login/api.ts | 20 +++++++++++++++++++ .../support/user/account/login/index.ts | 4 ++-- .../global/openapi/support/wallet/bill/api.ts | 2 +- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/packages/global/core/chat/helperBot/type.ts b/packages/global/core/chat/helperBot/type.ts index 26ee95ada6..96383c78a9 100644 --- a/packages/global/core/chat/helperBot/type.ts +++ b/packages/global/core/chat/helperBot/type.ts @@ -49,7 +49,7 @@ const AIChatItemSchema = z.object({ }); export type AIChatItemType = z.infer; -const HelperBotChatRoleSchema = z.discriminatedUnion('obj', [ +const HelperBotChatRoleSchema = z.union([ UserChatItemSchema, SystemChatItemSchema, AIChatItemSchema diff --git a/packages/global/openapi/core/ai/sandbox/api.ts b/packages/global/openapi/core/ai/sandbox/api.ts index 9c50aa1526..418686b787 100644 --- a/packages/global/openapi/core/ai/sandbox/api.ts +++ b/packages/global/openapi/core/ai/sandbox/api.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; /** * 文件操作 - 统一请求体 */ -export const SandboxFileOperationBodySchema = z.discriminatedUnion('action', [ +export const SandboxFileOperationBodySchema = z.union([ z.object({ action: z.literal('list'), appId: z.string(), diff --git a/packages/global/openapi/core/app/common/api.ts b/packages/global/openapi/core/app/common/api.ts index 87ed2ba8e6..6fb39d5b0d 100644 --- a/packages/global/openapi/core/app/common/api.ts +++ b/packages/global/openapi/core/app/common/api.ts @@ -6,6 +6,21 @@ import { StoreEdgeItemTypeSchema } from '../../../../core/workflow/type/edge'; import { StoreNodeItemTypeSchema } from '../../../../core/workflow/type/node'; import { ShortUrlSchema } from '../../../../support/marketing/type'; import { z } from 'zod'; +import { FlowNodeOutputItemTypeSchema } from '../../../../core/workflow/type/io'; + +const OpenAPIFlowNodeOutputItemTypeSchema = FlowNodeOutputItemTypeSchema.omit({ + invalidCondition: true +}).extend({ + invalidCondition: z.any().optional().meta({ + description: 'Internal editor validation function. This field is not expected in API payloads.' + }) +}); + +const OpenAPIStoreNodeItemTypeSchema = StoreNodeItemTypeSchema.omit({ + outputs: true +}).extend({ + outputs: z.array(OpenAPIFlowNodeOutputItemTypeSchema) +}); /* Get App Permission */ export const GetAppPermissionQuerySchema = z.object({ @@ -14,6 +29,7 @@ export const GetAppPermissionQuerySchema = z.object({ description: '应用 ID' }) }); + export type GetAppPermissionQueryType = z.infer; export const GetAppPermissionResponseSchema = z.object({ @@ -58,7 +74,7 @@ export const CreateAppBodySchema = z example: AppTypeEnum.workflow, description: '应用类型' }), - modules: z.array(StoreNodeItemTypeSchema).meta({ + modules: z.array(OpenAPIStoreNodeItemTypeSchema).meta({ example: [], description: '应用节点配置' }), diff --git a/packages/global/openapi/core/chat/helperBot/api.ts b/packages/global/openapi/core/chat/helperBot/api.ts index 9f6911b172..e2039d8d58 100644 --- a/packages/global/openapi/core/chat/helperBot/api.ts +++ b/packages/global/openapi/core/chat/helperBot/api.ts @@ -59,11 +59,9 @@ export const HelperBotCompletionsParamsSchema = z.object({ name: z.string() }) ), - metadata: z.discriminatedUnion('type', [ - z.object({ - type: z.literal(HelperBotTypeEnum.topAgent), - data: topAgentParamsSchema - }) - ]) + metadata: z.object({ + type: z.literal(HelperBotTypeEnum.topAgent), + data: topAgentParamsSchema + }) }); export type HelperBotCompletionsParamsType = z.infer; diff --git a/packages/global/openapi/support/user/account/login/api.ts b/packages/global/openapi/support/user/account/login/api.ts index dd8ffa9b7e..9744e563aa 100644 --- a/packages/global/openapi/support/user/account/login/api.ts +++ b/packages/global/openapi/support/user/account/login/api.ts @@ -2,6 +2,26 @@ import { z } from 'zod'; import { OAuthEnum } from '../../../../../support/user/constant'; import { TrackRegisterParamsSchema } from '../../../../../support/marketing/type'; import { LanguageSchema } from '../../../../../common/i18n/type'; +import { TeamTmbItemSchema } from '../../../../../support/user/team/type'; +import { UserSchema } from '../../../../../support/user/type'; + +const OpenAPITeamTmbItemSchema = TeamTmbItemSchema.omit({ + permission: true +}).extend({ + permission: z.any().meta({ + description: '团队权限实例。返回值为服务端权限对象,文档中按任意结构展示。' + }) +}); + +export const OpenAPIUserSchema = UserSchema.omit({ + team: true, + permission: true +}).extend({ + team: OpenAPITeamTmbItemSchema, + permission: z.any().meta({ + description: '用户权限实例。返回值为服务端权限对象,文档中按任意结构展示。' + }) +}); export const LoginSuccessResponseSchema = z.object({ user: z.any().meta({ diff --git a/packages/global/openapi/support/user/account/login/index.ts b/packages/global/openapi/support/user/account/login/index.ts index b6531f5fa8..02a9b5dc4e 100644 --- a/packages/global/openapi/support/user/account/login/index.ts +++ b/packages/global/openapi/support/user/account/login/index.ts @@ -10,7 +10,7 @@ import { GetWXLoginQRResponseSchema, LoginSuccessResponseSchema } from './api'; -import { UserSchema } from '../../../../../support/user/type'; +import { OpenAPIUserSchema } from './api'; export const LoginPath: OpenAPIPath = { '/support/user/account/tokenLogin': { @@ -23,7 +23,7 @@ export const LoginPath: OpenAPIPath = { description: '成功获取用户信息', content: { 'application/json': { - schema: UserSchema + schema: OpenAPIUserSchema } } } diff --git a/packages/global/openapi/support/wallet/bill/api.ts b/packages/global/openapi/support/wallet/bill/api.ts index bd18e3e521..94b1cbe1d8 100644 --- a/packages/global/openapi/support/wallet/bill/api.ts +++ b/packages/global/openapi/support/wallet/bill/api.ts @@ -76,7 +76,7 @@ export const CreateExtractDatasetBillSchema = z discountCouponId: z.string().optional().meta({ description: '优惠券 ID(未使用)' }) }) .meta({ description: '额外数据集存储订单创建参数' }); -export const CreateBillPropsSchema = z.discriminatedUnion('type', [ +export const CreateBillPropsSchema = z.union([ CreateStandPlanBillSchema, CreateExtractPointsBillSchema, CreateExtractDatasetBillSchema