diff --git a/packages/core/src/writers/split-mode.ts b/packages/core/src/writers/split-mode.ts index 65385c0e3..916afa762 100644 --- a/packages/core/src/writers/split-mode.ts +++ b/packages/core/src/writers/split-mode.ts @@ -61,12 +61,7 @@ export const writeSplitMode = async ({ }); mockData += builder.importsMock({ implementation: implementationMock, - imports: [ - { - exports: importsMock, - dependency: relativeSchemasPath, - }, - ], + imports: [{ exports: imports, dependency: relativeSchemasPath }], specsName, hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, diff --git a/packages/core/src/writers/split-tags-mode.ts b/packages/core/src/writers/split-tags-mode.ts index 294d9e8f0..a9f4df21a 100644 --- a/packages/core/src/writers/split-tags-mode.ts +++ b/packages/core/src/writers/split-tags-mode.ts @@ -75,12 +75,7 @@ export const writeSplitTagsMode = async ({ }); mockData += builder.importsMock({ implementation: implementationMock, - imports: [ - { - exports: importsMock, - dependency: relativeSchemasPath, - }, - ], + imports: importsForBuilder, specsName, hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, diff --git a/packages/core/src/writers/tags-mode.ts b/packages/core/src/writers/tags-mode.ts index bda37f7ae..23929b8a1 100644 --- a/packages/core/src/writers/tags-mode.ts +++ b/packages/core/src/writers/tags-mode.ts @@ -50,18 +50,20 @@ export const writeTagsMode = async ({ ? upath.relativeSafe(dirname, getFileInfo(output.schemas).dirname) : './' + filename + '.schemas'; + const importsForBuilder = [ + { + exports: imports.filter( + (imp) => + !importsMock.some((impMock) => imp.name === impMock.name), + ), + dependency: schemasPathRelative, + }, + ]; + data += builder.imports({ client: output.client, implementation, - imports: [ - { - exports: imports.filter( - (imp) => - !importsMock.some((impMock) => imp.name === impMock.name), - ), - dependency: schemasPathRelative, - }, - ], + imports: importsForBuilder, specsName, hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, @@ -74,9 +76,7 @@ export const writeTagsMode = async ({ if (output.mock) { data += builder.importsMock({ implementation: implementationMock, - imports: [ - { exports: importsMock, dependency: schemasPathRelative }, - ], + imports: importsForBuilder, specsName, hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index f0f0df3b1..faac95739 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -74,6 +74,8 @@ export const generateMSW = ( const isResponseOverridable = value.includes(overrideVarName); + const returnType = response.definition.success; + const isTextPlain = response.contentTypes.includes('text/plain'); const functionName = `get${pascal(operationId)}Mock`; @@ -104,7 +106,7 @@ export const ${handlerName} = http.${verb}('${route}', async () => { implementation: { function: value && value !== 'undefined' - ? `export const ${functionName} = (${isResponseOverridable ? `overrideResponse?: any` : ''}) => (${value})\n\n` + ? `export const ${functionName} = (${isResponseOverridable ? `overrideResponse?: any` : ''}): ${returnType} => (${value})\n\n` : '', handlerName: handlerName, handler: handlerImplementation,