From 11aa7eab0f7a79786c8a560dddc9e7330b8d8913 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Mon, 13 May 2024 09:23:00 +0200 Subject: [PATCH 1/9] feat(msw): split polymorphic mocks into its own functions --- packages/mock/src/faker/getters/combine.ts | 9 +++++++-- packages/mock/src/faker/getters/object.ts | 6 ++++++ packages/mock/src/faker/getters/scalar.ts | 6 ++++++ packages/mock/src/faker/resolvers/value.ts | 22 ++++++++++++++++++++++ packages/mock/src/msw/index.ts | 12 +++++++----- packages/mock/src/msw/mocks.ts | 8 +++++++- packages/mock/src/types.ts | 1 + 7 files changed, 56 insertions(+), 8 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 7461765a4..9ab230a1e 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -5,8 +5,8 @@ import { MockOptions, } from '@orval/core'; import omit from 'lodash.omit'; +import { MockDefinition, MockSchemaObject } from '../../types'; import { resolveMockValue } from '../resolvers'; -import { MockSchemaObject } from '../../types'; export const combineSchemasMock = ({ item, @@ -18,6 +18,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, + functions, }: { item: MockSchemaObject; separator: 'allOf' | 'oneOf' | 'anyOf'; @@ -33,7 +34,8 @@ export const combineSchemasMock = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; -}) => { + functions: string[]; +}): MockDefinition => { let combineImports: GeneratorImport[] = []; let includedProperties: string[] = (combine?.includedProperties ?? []).slice( 0, @@ -56,6 +58,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, + functions, }) : undefined; @@ -93,6 +96,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, + functions, }); combineImports.push(...resolvedValue.imports); @@ -165,5 +169,6 @@ export const combineSchemasMock = ({ imports: combineImports, name: item.name, includedProperties, + functions, }; }; diff --git a/packages/mock/src/faker/getters/object.ts b/packages/mock/src/faker/getters/object.ts index d4e7c0db6..3f38404d5 100644 --- a/packages/mock/src/faker/getters/object.ts +++ b/packages/mock/src/faker/getters/object.ts @@ -23,6 +23,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, + functions, }: { item: MockSchemaObject; operationId: string; @@ -37,6 +38,7 @@ export const getMockObject = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; + functions: string[]; }): MockDefinition => { if (isReference(item)) { return resolveMockValue({ @@ -51,6 +53,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, + functions, }); } @@ -66,6 +69,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, + functions, }); } @@ -113,6 +117,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, + functions, }); imports.push(...resolvedValue.imports); @@ -170,6 +175,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, + functions, }); return { diff --git a/packages/mock/src/faker/getters/scalar.ts b/packages/mock/src/faker/getters/scalar.ts index 944b5f859..e3ab3355a 100644 --- a/packages/mock/src/faker/getters/scalar.ts +++ b/packages/mock/src/faker/getters/scalar.ts @@ -25,6 +25,7 @@ export const getMockScalar = ({ combine, context, existingReferencedProperties, + functions, }: { item: MockSchemaObject; imports: GeneratorImport[]; @@ -40,6 +41,7 @@ export const getMockScalar = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; + functions: string[]; }): MockDefinition => { // Add the property to the existing properties to validate on object recursion if (item.isRef) { @@ -141,6 +143,7 @@ export const getMockScalar = ({ enums, imports: resolvedImports, name, + functions: funcs, } = resolveMockValue({ schema: { ...item.items, @@ -154,6 +157,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, + functions, }); if (enums) { @@ -201,6 +205,7 @@ export const getMockScalar = ({ `}, (_, i) => i + 1).map(() => (${mapValue}))`, imports: resolvedImports, name: item.name, + functions: funcs, }; } @@ -256,6 +261,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, + functions, }); } } diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 235a28761..4b823a738 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -4,11 +4,13 @@ import { getRefInfo, isReference, MockOptions, + pascal, } from '@orval/core'; import get from 'lodash.get'; import { SchemaObject } from 'openapi3-ts/oas30'; import { getMockScalar } from '../getters/scalar'; import { MockDefinition, MockSchemaObject } from '../../types'; +import { overrideVarName } from '../getters'; const isRegex = (key: string) => key[0] === '/' && key[key.length - 1] === '/'; @@ -56,6 +58,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, + functions, }: { schema: MockSchemaObject; operationId: string; @@ -70,6 +73,7 @@ export const resolveMockValue = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; + functions: string[]; }): MockDefinition & { type?: string } => { if (isReference(schema)) { const { @@ -99,7 +103,24 @@ export const resolveMockValue = ({ }, imports, existingReferencedProperties, + functions, }); + if (newSchema.allOf) { + const hasOverride = scalar.value.includes(overrideVarName); + const funcName = `get${pascal(operationId)}Response${pascal(scalar.name)}Mock`; + const originalValue = scalar.value; + scalar.value = `${funcName}(${hasOverride ? `${overrideVarName}` : ''})`; + if ( + scalar.functions.some((f) => f.includes(`export const ${funcName}`)) + ) { + scalar.value = `...${scalar.value}`; + } else { + const args = hasOverride ? `${overrideVarName}: any` : ''; + const func = `export const ${funcName} = (${args}): ${scalar.name} => (${originalValue});`; + scalar.functions.push(func); + } + scalar.imports.push({ name: scalar.name }); + } return { ...scalar, @@ -116,6 +137,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, + functions, }); return { diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index 249426b48..ccb17cfcf 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -1,4 +1,5 @@ import { + ClientMockGeneratorBuilder, generateDependencyImports, GenerateMockImports, GeneratorDependency, @@ -9,11 +10,10 @@ import { isObject, pascal, ResReqTypesValue, - ClientMockGeneratorBuilder, } from '@orval/core'; +import { getDelay } from '../delay'; import { getRouteMSW, overrideVarName } from '../faker/getters'; import { getMockDefinition, getMockOptionsDataOverride } from './mocks'; -import { getDelay } from '../delay'; const getMSWDependencies = (locale?: string): GeneratorDependency[] => [ { @@ -60,7 +60,7 @@ const generateDefinition = ( responses: ResReqTypesValue[], contentTypes: string[], ) => { - const { definitions, definition, imports } = getMockDefinition({ + const { definitions, definition, imports, functions } = getMockDefinition({ operationId, tags, returnType, @@ -90,9 +90,11 @@ const generateDefinition = ( const getResponseMockFunctionName = `${getResponseMockFunctionNameBase}${pascal(name)}`; const handlerName = `${handlerNameBase}${pascal(name)}`; + const mockFunctions = functions.length ? `${functions.join('\n\n')}\n\n` : ''; + const mockImplementation = isReturnHttpResponse - ? `export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: any = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` - : ''; + ? `${mockFunctions}export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: any = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` + : mockFunctions; const delay = getDelay(override, !isFunction(mock) ? mock : undefined); const handlerImplementation = ` diff --git a/packages/mock/src/msw/mocks.ts b/packages/mock/src/msw/mocks.ts index 6eda94610..5757569db 100644 --- a/packages/mock/src/msw/mocks.ts +++ b/packages/mock/src/msw/mocks.ts @@ -189,6 +189,7 @@ export const getResponsesMockDefinition = ({ } : context, existingReferencedProperties: [], + functions: [], }); acc.imports.push(...scalar.imports); @@ -197,11 +198,15 @@ export const getResponsesMockDefinition = ({ ? transformer(scalar.value, returnType) : scalar.value.toString(), ); + if (scalar.functions) { + acc.functions.push(...scalar.functions); + } return acc; }, { definitions: [] as string[], + functions: [] as string[], imports: [] as GeneratorImport[], }, ); @@ -233,7 +238,7 @@ export const getMockDefinition = ({ override, ); - const { definitions, imports } = getResponsesMockDefinition({ + const { definitions, imports, functions } = getResponsesMockDefinition({ operationId, tags, returnType, @@ -249,6 +254,7 @@ export const getMockDefinition = ({ definition: '[' + definitions.join(', ') + ']', definitions, imports, + functions, }; }; diff --git a/packages/mock/src/types.ts b/packages/mock/src/types.ts index 6573430cf..bffc5f89d 100644 --- a/packages/mock/src/types.ts +++ b/packages/mock/src/types.ts @@ -8,6 +8,7 @@ export interface MockDefinition { name: string; overrided?: boolean; includedProperties?: string[]; + functions: string[]; } export type MockSchemaObject = SchemaObject & { From a7023c44644ef4c8bd30e10c435cf9525927b3bd Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Mon, 13 May 2024 12:01:06 +0200 Subject: [PATCH 2/9] fix: formatting --- packages/hono/src/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/hono/src/index.ts b/packages/hono/src/index.ts index 0b57456b6..d268e712b 100644 --- a/packages/hono/src/index.ts +++ b/packages/hono/src/index.ts @@ -199,14 +199,17 @@ const getHandlerFix = ({ const getVerbOptionGroupByTag = ( verbOptions: Record, ) => { - return Object.values(verbOptions).reduce((acc, value) => { - const tag = value.tags[0]; - if (!acc[tag]) { - acc[tag] = []; - } - acc[tag].push(value); - return acc; - }, {} as Record); + return Object.values(verbOptions).reduce( + (acc, value) => { + const tag = value.tags[0]; + if (!acc[tag]) { + acc[tag] = []; + } + acc[tag].push(value); + return acc; + }, + {} as Record, + ); }; const generateHandlers = async ( From 3f027984816c75c8e351805f0536dfd44097897c Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Wed, 15 May 2024 15:50:34 +0200 Subject: [PATCH 3/9] fix: remove extra comma --- packages/mock/src/faker/getters/combine.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 9ab230a1e..0838ceb30 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -113,9 +113,9 @@ export const combineSchemasMock = ({ } if (itemResolvedValue?.value && separator !== 'oneOf' && isLastElement) { - currentValue = `${currentValue}${ - itemResolvedValue?.value ? `,${itemResolvedValue.value}` : '' - }`; + currentValue = `${currentValue ? `${currentValue},` : ''} + ${itemResolvedValue.value} + `; } const isObjectBounds = From c2fdaa1eb6a20ad8966314e7ae0b4f5218af7f84 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Wed, 15 May 2024 17:04:32 +0200 Subject: [PATCH 4/9] fix: whitespace --- packages/mock/src/faker/getters/combine.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 0838ceb30..6810c3bd3 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -113,9 +113,7 @@ export const combineSchemasMock = ({ } if (itemResolvedValue?.value && separator !== 'oneOf' && isLastElement) { - currentValue = `${currentValue ? `${currentValue},` : ''} - ${itemResolvedValue.value} - `; + currentValue = `${currentValue ? `${currentValue},` : ''}${itemResolvedValue.value}`; } const isObjectBounds = From ef6c5b5450ab674d8f57572554e0591aeae50cf1 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Thu, 16 May 2024 12:52:46 +0200 Subject: [PATCH 5/9] fix: split objects that combine with oneOf, rename functions --- packages/mock/src/faker/getters/combine.ts | 9 ++--- packages/mock/src/faker/getters/object.ts | 12 +++--- packages/mock/src/faker/getters/scalar.ts | 10 ++--- packages/mock/src/faker/resolvers/value.ts | 47 ++++++++++++++-------- packages/mock/src/msw/index.ts | 4 +- packages/mock/src/msw/mocks.ts | 6 +-- packages/mock/src/types.ts | 1 - 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 6810c3bd3..8cd717ff7 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -18,7 +18,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }: { item: MockSchemaObject; separator: 'allOf' | 'oneOf' | 'anyOf'; @@ -34,7 +34,7 @@ export const combineSchemasMock = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - functions: string[]; + splitMockImplementions: string[]; }): MockDefinition => { let combineImports: GeneratorImport[] = []; let includedProperties: string[] = (combine?.includedProperties ?? []).slice( @@ -58,7 +58,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }) : undefined; @@ -96,7 +96,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); combineImports.push(...resolvedValue.imports); @@ -167,6 +167,5 @@ export const combineSchemasMock = ({ imports: combineImports, name: item.name, includedProperties, - functions, }; }; diff --git a/packages/mock/src/faker/getters/object.ts b/packages/mock/src/faker/getters/object.ts index e004748ba..05d6f85bd 100644 --- a/packages/mock/src/faker/getters/object.ts +++ b/packages/mock/src/faker/getters/object.ts @@ -23,7 +23,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride = false, }: { item: MockSchemaObject; @@ -39,7 +39,7 @@ export const getMockObject = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - functions: string[]; + splitMockImplementions: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -56,7 +56,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); } @@ -72,7 +72,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); } @@ -120,7 +120,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); imports.push(...resolvedValue.imports); @@ -180,7 +180,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); return { diff --git a/packages/mock/src/faker/getters/scalar.ts b/packages/mock/src/faker/getters/scalar.ts index f92ba4a90..947b94881 100644 --- a/packages/mock/src/faker/getters/scalar.ts +++ b/packages/mock/src/faker/getters/scalar.ts @@ -25,7 +25,7 @@ export const getMockScalar = ({ combine, context, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride = false, }: { item: MockSchemaObject; @@ -42,7 +42,7 @@ export const getMockScalar = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - functions: string[]; + splitMockImplementions: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -146,7 +146,6 @@ export const getMockScalar = ({ enums, imports: resolvedImports, name, - functions: funcs, } = resolveMockValue({ schema: { ...item.items, @@ -160,7 +159,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, }); if (enums) { @@ -208,7 +207,6 @@ export const getMockScalar = ({ `}, (_, i) => i + 1).map(() => (${mapValue}))`, imports: resolvedImports, name: item.name, - functions: funcs, }; } @@ -264,7 +262,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride, }); } diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 0ed5660d5..7a5f88d9a 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -7,7 +7,7 @@ import { pascal, } from '@orval/core'; import get from 'lodash.get'; -import { SchemaObject } from 'openapi3-ts/oas30'; +import { ReferenceObject, SchemaObject } from 'openapi3-ts/oas30'; import { getMockScalar } from '../getters/scalar'; import { MockDefinition, MockSchemaObject } from '../../types'; import { overrideVarName } from '../getters'; @@ -58,7 +58,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride, }: { schema: MockSchemaObject; @@ -74,7 +74,7 @@ export const resolveMockValue = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - functions: string[]; + splitMockImplementions: string[]; allowOverride?: boolean; }): MockDefinition & { type?: string } => { if (isReference(schema)) { @@ -84,7 +84,7 @@ export const resolveMockValue = ({ refPaths, } = getRefInfo(schema.$ref, context); - const schemaRef = get(context.specs[specKey], refPaths); + const schemaRef = get(context.specs[specKey], refPaths as string[]); const newSchema = { ...schemaRef, @@ -105,23 +105,36 @@ export const resolveMockValue = ({ }, imports, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride, }); - if (newSchema.allOf) { - const funcName = `get${pascal(operationId)}Response${pascal(scalar.name)}Mock`; - const originalValue = scalar.value; - scalar.value = `${funcName}(${allowOverride ? `${overrideVarName}` : ''})`; + if ( + scalar.value && + newSchema.type === 'object' && + combine?.separator === 'oneOf' + ) { + const funcName = `get${pascal(operationId)}Response${pascal(newSchema.name)}Mock`; if ( - scalar.functions?.some((f) => f.includes(`export const ${funcName}`)) + !splitMockImplementions?.some((f) => + f.includes(`export const ${funcName}`), + ) ) { - scalar.value = `...${scalar.value}`; - } else { - const args = `${overrideVarName}: Partial<${scalar.name}> = {}`; - const func = `export const ${funcName} = (${args}): ${scalar.name} => ({...${originalValue}, ...${overrideVarName}});`; - scalar.functions?.push(func); + const discriminatedProperty = newSchema.discriminator?.propertyName; + if (newSchema.name === 'CaseCanceledReason') console.log(newSchema); + let type = `Partial<${newSchema.name}>`; + if (discriminatedProperty) { + type = `Omit<${type}, '${discriminatedProperty}'>`; + } + + const args = `${overrideVarName}: ${type} = {}`; + const value = newSchema.oneOf + ? `faker.helpers.arrayElement([${scalar.value}])` + : scalar.value; + const func = `export const ${funcName} = (${args}): ${newSchema.name} => ({...${value}, ...${overrideVarName}});`; + splitMockImplementions?.push(func); } - scalar.imports.push({ name: scalar.name }); + scalar.value = `{...${funcName}()}`; + scalar.imports.push({ name: newSchema.name }); } return { @@ -139,7 +152,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - functions, + splitMockImplementions, allowOverride, }); diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index bc676932b..902f8a538 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -90,7 +90,9 @@ const generateDefinition = ( const getResponseMockFunctionName = `${getResponseMockFunctionNameBase}${pascal(name)}`; const handlerName = `${handlerNameBase}${pascal(name)}`; - const mockFunctions = functions.length ? `${functions.join('\n\n')}\n\n` : ''; + const mockFunctions = functions.length + ? `//#region ${getResponseMockFunctionName} sub functions\n${functions.join('\n\n')}\n//#endregion\n\n` + : ''; const mockImplementation = isReturnHttpResponse ? `${mockFunctions}export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: Partial< ${returnType} > = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` diff --git a/packages/mock/src/msw/mocks.ts b/packages/mock/src/msw/mocks.ts index 5d0d4bbbd..d94d4487c 100644 --- a/packages/mock/src/msw/mocks.ts +++ b/packages/mock/src/msw/mocks.ts @@ -134,6 +134,7 @@ export const getResponsesMockDefinition = ({ context: ContextSpecs; mockOptions?: GlobalMockOptions; }) => { + // console.log(responses); return responses.reduce( ( acc, @@ -189,7 +190,7 @@ export const getResponsesMockDefinition = ({ } : context, existingReferencedProperties: [], - functions: [], + splitMockImplementions: acc.functions, allowOverride: true, }); @@ -199,9 +200,6 @@ export const getResponsesMockDefinition = ({ ? transformer(scalar.value, returnType) : scalar.value.toString(), ); - if (scalar.functions) { - acc.functions.push(...scalar.functions); - } return acc; }, diff --git a/packages/mock/src/types.ts b/packages/mock/src/types.ts index 8b754380d..6573430cf 100644 --- a/packages/mock/src/types.ts +++ b/packages/mock/src/types.ts @@ -8,7 +8,6 @@ export interface MockDefinition { name: string; overrided?: boolean; includedProperties?: string[]; - functions?: string[]; } export type MockSchemaObject = SchemaObject & { From 7e4e4bcec7fdc3980ff9fec817e9163041d94deb Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Thu, 16 May 2024 13:43:41 +0200 Subject: [PATCH 6/9] fix: issue with duplicate functions in multi resposes --- packages/mock/src/faker/getters/combine.ts | 8 ++++---- packages/mock/src/faker/getters/object.ts | 12 ++++++------ packages/mock/src/faker/getters/scalar.ts | 8 ++++---- packages/mock/src/faker/resolvers/value.ts | 12 ++++++------ packages/mock/src/msw/index.ts | 21 ++++++++++++++++----- packages/mock/src/msw/mocks.ts | 11 +++++++---- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 8cd717ff7..918204081 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -18,7 +18,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations, }: { item: MockSchemaObject; separator: 'allOf' | 'oneOf' | 'anyOf'; @@ -34,7 +34,7 @@ export const combineSchemasMock = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - splitMockImplementions: string[]; + allSplitMockImplementations: string[]; }): MockDefinition => { let combineImports: GeneratorImport[] = []; let includedProperties: string[] = (combine?.includedProperties ?? []).slice( @@ -58,7 +58,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }) : undefined; @@ -96,7 +96,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); combineImports.push(...resolvedValue.imports); diff --git a/packages/mock/src/faker/getters/object.ts b/packages/mock/src/faker/getters/object.ts index 05d6f85bd..88cd70e56 100644 --- a/packages/mock/src/faker/getters/object.ts +++ b/packages/mock/src/faker/getters/object.ts @@ -23,7 +23,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations, allowOverride = false, }: { item: MockSchemaObject; @@ -39,7 +39,7 @@ export const getMockObject = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - splitMockImplementions: string[]; + allSplitMockImplementations: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -56,7 +56,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); } @@ -72,7 +72,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); } @@ -120,7 +120,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); imports.push(...resolvedValue.imports); @@ -180,7 +180,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); return { diff --git a/packages/mock/src/faker/getters/scalar.ts b/packages/mock/src/faker/getters/scalar.ts index 947b94881..2e1117462 100644 --- a/packages/mock/src/faker/getters/scalar.ts +++ b/packages/mock/src/faker/getters/scalar.ts @@ -25,7 +25,7 @@ export const getMockScalar = ({ combine, context, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, allowOverride = false, }: { item: MockSchemaObject; @@ -42,7 +42,7 @@ export const getMockScalar = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - splitMockImplementions: string[]; + allSplitMockImplementations: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -159,7 +159,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, }); if (enums) { @@ -262,7 +262,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, allowOverride, }); } diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 7a5f88d9a..9797440b8 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -58,7 +58,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations, allowOverride, }: { schema: MockSchemaObject; @@ -74,7 +74,7 @@ export const resolveMockValue = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - splitMockImplementions: string[]; + allSplitMockImplementations: string[]; allowOverride?: boolean; }): MockDefinition & { type?: string } => { if (isReference(schema)) { @@ -105,7 +105,7 @@ export const resolveMockValue = ({ }, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations, allowOverride, }); if ( @@ -115,7 +115,7 @@ export const resolveMockValue = ({ ) { const funcName = `get${pascal(operationId)}Response${pascal(newSchema.name)}Mock`; if ( - !splitMockImplementions?.some((f) => + !allSplitMockImplementations?.some((f) => f.includes(`export const ${funcName}`), ) ) { @@ -131,7 +131,7 @@ export const resolveMockValue = ({ ? `faker.helpers.arrayElement([${scalar.value}])` : scalar.value; const func = `export const ${funcName} = (${args}): ${newSchema.name} => ({...${value}, ...${overrideVarName}});`; - splitMockImplementions?.push(func); + allSplitMockImplementations?.push(func); } scalar.value = `{...${funcName}()}`; scalar.imports.push({ name: newSchema.name }); @@ -152,7 +152,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - splitMockImplementions, + allSplitMockImplementations: allSplitMockImplementations, allowOverride, }); diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index 902f8a538..f9bfd49a4 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -59,8 +59,10 @@ const generateDefinition = ( responseImports: GeneratorImport[], responses: ResReqTypesValue[], contentTypes: string[], + allSplitMockImplementations: string[], ) => { - const { definitions, definition, imports, functions } = getMockDefinition({ + const splitMockImplementations = [...allSplitMockImplementations]; + const { definitions, definition, imports } = getMockDefinition({ operationId, tags, returnType, @@ -69,6 +71,7 @@ const generateDefinition = ( override, context, mockOptions: !isFunction(mock) ? mock : undefined, + allSplitMockImplementations: splitMockImplementations, }); const mockData = getMockOptionsDataOverride(operationId, override); @@ -90,13 +93,17 @@ const generateDefinition = ( const getResponseMockFunctionName = `${getResponseMockFunctionNameBase}${pascal(name)}`; const handlerName = `${handlerNameBase}${pascal(name)}`; - const mockFunctions = functions.length - ? `//#region ${getResponseMockFunctionName} sub functions\n${functions.join('\n\n')}\n//#endregion\n\n` + const addedSplitMockImplementations = splitMockImplementations.slice( + allSplitMockImplementations.length, + ); + allSplitMockImplementations.push(...addedSplitMockImplementations); + const mockImplementations = addedSplitMockImplementations.length + ? `//#region ${getResponseMockFunctionName} sub functions\n${addedSplitMockImplementations.join('\n\n')}\n//#endregion\n\n` : ''; const mockImplementation = isReturnHttpResponse - ? `${mockFunctions}export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: Partial< ${returnType} > = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` - : mockFunctions; + ? `${mockImplementations}export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: Partial< ${returnType} > = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` + : mockImplementations; const delay = getDelay(override, !isFunction(mock) ? mock : undefined); const handlerImplementation = ` @@ -163,6 +170,8 @@ export const generateMSW = ( const handlerName = `get${pascal(operationId)}MockHandler`; const getResponseMockFunctionName = `get${pascal(operationId)}ResponseMock`; + const splitMockImplementations: string[] = []; + const baseDefinition = generateDefinition( '', route, @@ -175,6 +184,7 @@ export const generateMSW = ( response.imports, response.types.success, response.contentTypes, + splitMockImplementations, ); const mockImplementations = [baseDefinition.implementation.function]; @@ -200,6 +210,7 @@ export const generateMSW = ( response.imports, [statusResponse], [statusResponse.contentType], + splitMockImplementations, ); mockImplementations.push(definition.implementation.function); handlerImplementations.push(definition.implementation.handler); diff --git a/packages/mock/src/msw/mocks.ts b/packages/mock/src/msw/mocks.ts index d94d4487c..5f004ab2d 100644 --- a/packages/mock/src/msw/mocks.ts +++ b/packages/mock/src/msw/mocks.ts @@ -123,6 +123,7 @@ export const getResponsesMockDefinition = ({ transformer, context, mockOptions, + allSplitMockImplementations, }: { operationId: string; tags: string[]; @@ -133,6 +134,7 @@ export const getResponsesMockDefinition = ({ transformer?: (value: unknown, definition: string) => string; context: ContextSpecs; mockOptions?: GlobalMockOptions; + allSplitMockImplementations: string[]; }) => { // console.log(responses); return responses.reduce( @@ -190,7 +192,7 @@ export const getResponsesMockDefinition = ({ } : context, existingReferencedProperties: [], - splitMockImplementions: acc.functions, + allSplitMockImplementations: allSplitMockImplementations, allowOverride: true, }); @@ -205,7 +207,6 @@ export const getResponsesMockDefinition = ({ }, { definitions: [] as string[], - functions: [] as string[], imports: [] as GeneratorImport[], }, ); @@ -221,6 +222,7 @@ export const getMockDefinition = ({ transformer, context, mockOptions, + allSplitMockImplementations, }: { operationId: string; tags: string[]; @@ -231,13 +233,14 @@ export const getMockDefinition = ({ transformer?: (value: unknown, definition: string) => string; context: ContextSpecs; mockOptions?: GlobalMockOptions; + allSplitMockImplementations: string[]; }) => { const mockOptionsWithoutFunc = getMockWithoutFunc( context.specs[context.specKey], override, ); - const { definitions, imports, functions } = getResponsesMockDefinition({ + const { definitions, imports } = getResponsesMockDefinition({ operationId, tags, returnType, @@ -247,13 +250,13 @@ export const getMockDefinition = ({ transformer, context, mockOptions, + allSplitMockImplementations, }); return { definition: '[' + definitions.join(', ') + ']', definitions, imports, - functions, }; }; From 29cded207cad3b1f0421cdb7718e870a9ba6212c Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Thu, 16 May 2024 14:23:15 +0200 Subject: [PATCH 7/9] fix: import with correct specKey --- packages/mock/src/faker/resolvers/value.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 9797440b8..3fbf58e37 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -134,7 +134,7 @@ export const resolveMockValue = ({ allSplitMockImplementations?.push(func); } scalar.value = `{...${funcName}()}`; - scalar.imports.push({ name: newSchema.name }); + scalar.imports.push({ name: newSchema.name, specKey }); } return { From c3a6d8adadcd5c2bc9dccec6fc525c1c27801974 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Thu, 16 May 2024 14:34:56 +0200 Subject: [PATCH 8/9] fix: check rootKey --- packages/mock/src/faker/getters/combine.ts | 8 ++++---- packages/mock/src/faker/getters/object.ts | 12 +++++------ packages/mock/src/faker/getters/scalar.ts | 8 ++++---- packages/mock/src/faker/resolvers/value.ts | 24 +++++++++++++--------- packages/mock/src/msw/index.ts | 10 ++++----- packages/mock/src/msw/mocks.ts | 12 +++++------ 6 files changed, 39 insertions(+), 35 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 918204081..a5c793751 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -18,7 +18,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations, + splitMockImplementations, }: { item: MockSchemaObject; separator: 'allOf' | 'oneOf' | 'anyOf'; @@ -34,7 +34,7 @@ export const combineSchemasMock = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; }): MockDefinition => { let combineImports: GeneratorImport[] = []; let includedProperties: string[] = (combine?.includedProperties ?? []).slice( @@ -58,7 +58,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }) : undefined; @@ -96,7 +96,7 @@ export const combineSchemasMock = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); combineImports.push(...resolvedValue.imports); diff --git a/packages/mock/src/faker/getters/object.ts b/packages/mock/src/faker/getters/object.ts index 88cd70e56..d1cfc7cfb 100644 --- a/packages/mock/src/faker/getters/object.ts +++ b/packages/mock/src/faker/getters/object.ts @@ -23,7 +23,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations, + splitMockImplementations, allowOverride = false, }: { item: MockSchemaObject; @@ -39,7 +39,7 @@ export const getMockObject = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -56,7 +56,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); } @@ -72,7 +72,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); } @@ -120,7 +120,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); imports.push(...resolvedValue.imports); @@ -180,7 +180,7 @@ export const getMockObject = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); return { diff --git a/packages/mock/src/faker/getters/scalar.ts b/packages/mock/src/faker/getters/scalar.ts index 2e1117462..40caa8bf9 100644 --- a/packages/mock/src/faker/getters/scalar.ts +++ b/packages/mock/src/faker/getters/scalar.ts @@ -25,7 +25,7 @@ export const getMockScalar = ({ combine, context, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, allowOverride = false, }: { item: MockSchemaObject; @@ -42,7 +42,7 @@ export const getMockScalar = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; // This is used to add the overrideResponse to the object allowOverride?: boolean; }): MockDefinition => { @@ -159,7 +159,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, }); if (enums) { @@ -262,7 +262,7 @@ export const getMockScalar = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, allowOverride, }); } diff --git a/packages/mock/src/faker/resolvers/value.ts b/packages/mock/src/faker/resolvers/value.ts index 3fbf58e37..8f0f8dc5a 100644 --- a/packages/mock/src/faker/resolvers/value.ts +++ b/packages/mock/src/faker/resolvers/value.ts @@ -3,14 +3,15 @@ import { GeneratorImport, getRefInfo, isReference, + isRootKey, MockOptions, pascal, } from '@orval/core'; import get from 'lodash.get'; -import { ReferenceObject, SchemaObject } from 'openapi3-ts/oas30'; -import { getMockScalar } from '../getters/scalar'; +import { SchemaObject } from 'openapi3-ts/oas30'; import { MockDefinition, MockSchemaObject } from '../../types'; import { overrideVarName } from '../getters'; +import { getMockScalar } from '../getters/scalar'; const isRegex = (key: string) => key[0] === '/' && key[key.length - 1] === '/'; @@ -58,7 +59,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations, + splitMockImplementations, allowOverride, }: { schema: MockSchemaObject; @@ -74,7 +75,7 @@ export const resolveMockValue = ({ // This is used to prevent recursion when combining schemas // When an element is added to the array, it means on this iteration, we've already seen this property existingReferencedProperties: string[]; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; allowOverride?: boolean; }): MockDefinition & { type?: string } => { if (isReference(schema)) { @@ -105,7 +106,7 @@ export const resolveMockValue = ({ }, imports, existingReferencedProperties, - allSplitMockImplementations, + splitMockImplementations, allowOverride, }); if ( @@ -115,12 +116,12 @@ export const resolveMockValue = ({ ) { const funcName = `get${pascal(operationId)}Response${pascal(newSchema.name)}Mock`; if ( - !allSplitMockImplementations?.some((f) => + !splitMockImplementations?.some((f) => f.includes(`export const ${funcName}`), ) ) { const discriminatedProperty = newSchema.discriminator?.propertyName; - if (newSchema.name === 'CaseCanceledReason') console.log(newSchema); + let type = `Partial<${newSchema.name}>`; if (discriminatedProperty) { type = `Omit<${type}, '${discriminatedProperty}'>`; @@ -131,10 +132,13 @@ export const resolveMockValue = ({ ? `faker.helpers.arrayElement([${scalar.value}])` : scalar.value; const func = `export const ${funcName} = (${args}): ${newSchema.name} => ({...${value}, ...${overrideVarName}});`; - allSplitMockImplementations?.push(func); + splitMockImplementations?.push(func); } scalar.value = `{...${funcName}()}`; - scalar.imports.push({ name: newSchema.name, specKey }); + scalar.imports.push({ + name: newSchema.name, + specKey: isRootKey(specKey, context.target) ? undefined : specKey, + }); } return { @@ -152,7 +156,7 @@ export const resolveMockValue = ({ context, imports, existingReferencedProperties, - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, allowOverride, }); diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index f9bfd49a4..b0da1b309 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -59,9 +59,9 @@ const generateDefinition = ( responseImports: GeneratorImport[], responses: ResReqTypesValue[], contentTypes: string[], - allSplitMockImplementations: string[], + splitMockImplementations: string[], ) => { - const splitMockImplementations = [...allSplitMockImplementations]; + const oldSplitMockImplementations = [...splitMockImplementations]; const { definitions, definition, imports } = getMockDefinition({ operationId, tags, @@ -71,7 +71,7 @@ const generateDefinition = ( override, context, mockOptions: !isFunction(mock) ? mock : undefined, - allSplitMockImplementations: splitMockImplementations, + splitMockImplementations, }); const mockData = getMockOptionsDataOverride(operationId, override); @@ -94,9 +94,9 @@ const generateDefinition = ( const handlerName = `${handlerNameBase}${pascal(name)}`; const addedSplitMockImplementations = splitMockImplementations.slice( - allSplitMockImplementations.length, + oldSplitMockImplementations.length, ); - allSplitMockImplementations.push(...addedSplitMockImplementations); + splitMockImplementations.push(...addedSplitMockImplementations); const mockImplementations = addedSplitMockImplementations.length ? `//#region ${getResponseMockFunctionName} sub functions\n${addedSplitMockImplementations.join('\n\n')}\n//#endregion\n\n` : ''; diff --git a/packages/mock/src/msw/mocks.ts b/packages/mock/src/msw/mocks.ts index 5f004ab2d..7e799711d 100644 --- a/packages/mock/src/msw/mocks.ts +++ b/packages/mock/src/msw/mocks.ts @@ -123,7 +123,7 @@ export const getResponsesMockDefinition = ({ transformer, context, mockOptions, - allSplitMockImplementations, + splitMockImplementations, }: { operationId: string; tags: string[]; @@ -134,7 +134,7 @@ export const getResponsesMockDefinition = ({ transformer?: (value: unknown, definition: string) => string; context: ContextSpecs; mockOptions?: GlobalMockOptions; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; }) => { // console.log(responses); return responses.reduce( @@ -192,7 +192,7 @@ export const getResponsesMockDefinition = ({ } : context, existingReferencedProperties: [], - allSplitMockImplementations: allSplitMockImplementations, + splitMockImplementations, allowOverride: true, }); @@ -222,7 +222,7 @@ export const getMockDefinition = ({ transformer, context, mockOptions, - allSplitMockImplementations, + splitMockImplementations, }: { operationId: string; tags: string[]; @@ -233,7 +233,7 @@ export const getMockDefinition = ({ transformer?: (value: unknown, definition: string) => string; context: ContextSpecs; mockOptions?: GlobalMockOptions; - allSplitMockImplementations: string[]; + splitMockImplementations: string[]; }) => { const mockOptionsWithoutFunc = getMockWithoutFunc( context.specs[context.specKey], @@ -250,7 +250,7 @@ export const getMockDefinition = ({ transformer, context, mockOptions, - allSplitMockImplementations, + splitMockImplementations, }); return { From 3576c51e18bf40d945d4eea388baaf2b902ec593 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Fri, 17 May 2024 06:54:42 +0200 Subject: [PATCH 9/9] fix: remove region --- packages/mock/src/msw/index.ts | 2 +- packages/mock/src/msw/mocks.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index b0da1b309..7e4e46181 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -98,7 +98,7 @@ const generateDefinition = ( ); splitMockImplementations.push(...addedSplitMockImplementations); const mockImplementations = addedSplitMockImplementations.length - ? `//#region ${getResponseMockFunctionName} sub functions\n${addedSplitMockImplementations.join('\n\n')}\n//#endregion\n\n` + ? `${addedSplitMockImplementations.join('\n\n')}\n\n` : ''; const mockImplementation = isReturnHttpResponse diff --git a/packages/mock/src/msw/mocks.ts b/packages/mock/src/msw/mocks.ts index 7e799711d..30feff26b 100644 --- a/packages/mock/src/msw/mocks.ts +++ b/packages/mock/src/msw/mocks.ts @@ -136,7 +136,6 @@ export const getResponsesMockDefinition = ({ mockOptions?: GlobalMockOptions; splitMockImplementations: string[]; }) => { - // console.log(responses); return responses.reduce( ( acc,