From 848fe15477b91518a2880458d4b68833b7a19e34 Mon Sep 17 00:00:00 2001 From: Gosha Date: Sun, 8 Dec 2024 21:07:28 +0200 Subject: [PATCH] chore(dashboard): update create mock object from schema signature --- .../generate-preview/generate-preview.usecase.ts | 11 ++++------- .../test-workflow/test-workflow-tabs.tsx | 4 ++-- .../utils/schema/create-mock-object-from-schema.ts | 6 +++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts b/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts index 1aa4d771024..c8babebadca 100644 --- a/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts +++ b/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts @@ -134,13 +134,10 @@ export class GeneratePreviewUsecase { return finalPayload; } - const examplePayloadSchema = createMockObjectFromSchema( - { - type: 'object', - properties: { payload: workflow.payloadSchema }, - }, - true - ); + const examplePayloadSchema = createMockObjectFromSchema({ + type: 'object', + properties: { payload: workflow.payloadSchema }, + }); if (!examplePayloadSchema || Object.keys(examplePayloadSchema).length === 0) { return finalPayload; diff --git a/apps/dashboard/src/components/workflow-editor/test-workflow/test-workflow-tabs.tsx b/apps/dashboard/src/components/workflow-editor/test-workflow/test-workflow-tabs.tsx index 861ee5ee654..6656c03d1e1 100644 --- a/apps/dashboard/src/components/workflow-editor/test-workflow/test-workflow-tabs.tsx +++ b/apps/dashboard/src/components/workflow-editor/test-workflow/test-workflow-tabs.tsx @@ -23,8 +23,8 @@ export const TestWorkflowTabs = ({ testData }: { testData: WorkflowTestDataRespo const { workflow } = useFetchWorkflow({ workflowSlug, }); - const to = useMemo(() => createMockObjectFromSchema(testData.to, true), [testData]); - const payload = useMemo(() => createMockObjectFromSchema(testData.payload, true), [testData]); + const to = useMemo(() => createMockObjectFromSchema(testData.to), [testData]); + const payload = useMemo(() => createMockObjectFromSchema(testData.payload), [testData]); const form = useForm({ mode: 'onSubmit', resolver: zodResolver(buildDynamicFormSchema({ to: testData?.to ?? {} })), diff --git a/packages/shared/src/utils/schema/create-mock-object-from-schema.ts b/packages/shared/src/utils/schema/create-mock-object-from-schema.ts index 5a78122f7f0..4fbb9f6958f 100644 --- a/packages/shared/src/utils/schema/create-mock-object-from-schema.ts +++ b/packages/shared/src/utils/schema/create-mock-object-from-schema.ts @@ -17,9 +17,9 @@ import { JSONSchemaDto } from '../../dto'; */ export function createMockObjectFromSchema( schema: JSONSchemaDto, - safe = true, path = '', - depth = 0 + depth = 0, + safe = true ): Record { const MAX_DEPTH = 10; if (depth >= MAX_DEPTH) { @@ -48,7 +48,7 @@ export function createMockObjectFromSchema( if (definition.default) { acc[key] = definition.default; } else if (definition.type === 'object' && definition.properties) { - acc[key] = createMockObjectFromSchema(definition, safe, currentPath, depth + 1); + acc[key] = createMockObjectFromSchema(definition, currentPath, depth + 1); } else { acc[key] = `{{${currentPath}}}`; }