diff --git a/packages/core/src/getters/res-req-types.ts b/packages/core/src/getters/res-req-types.ts index b5a0ad0bd..87de2ba60 100644 --- a/packages/core/src/getters/res-req-types.ts +++ b/packages/core/src/getters/res-req-types.ts @@ -148,17 +148,10 @@ export const getResReqTypes = ( const isFormUrlEncoded = formUrlEncodedContentTypes.includes(contentType); - const imports = [ - ...resolvedValue.imports, - ...(resolvedValue.hasReadonlyProps - ? [{ name: 'NonReadonly' }] - : []), - ]; - if ((!isFormData && !isFormUrlEncoded) || !propName) { return { ...resolvedValue, - imports, + imports: resolvedValue.imports, contentType, }; } @@ -182,7 +175,7 @@ export const getResReqTypes = ( return { ...resolvedValue, - imports, + imports: resolvedValue.imports, formData, formUrlEncoded, contentType, diff --git a/packages/core/src/writers/schemas.ts b/packages/core/src/writers/schemas.ts index 45022dfb7..c0baacac3 100644 --- a/packages/core/src/writers/schemas.ts +++ b/packages/core/src/writers/schemas.ts @@ -130,7 +130,7 @@ export const writeSchemas = async ({ .sort() .join('\n'); - const fileContent = `${header}\n${exports}\n${getOrvalGeneratedTypes()}`; + const fileContent = `${header}\n${exports}`; await fs.writeFile(schemaFilePath, fileContent); } catch (e) { diff --git a/packages/core/src/writers/single-mode.ts b/packages/core/src/writers/single-mode.ts index 152db40b4..c1bee315d 100644 --- a/packages/core/src/writers/single-mode.ts +++ b/packages/core/src/writers/single-mode.ts @@ -8,6 +8,7 @@ import { upath, } from '../utils'; import { generateTarget } from './target'; +import { getOrvalGeneratedTypes } from './types'; export const writeSingleMode = async ({ builder, @@ -90,6 +91,11 @@ export const writeSingleMode = async ({ data += generateMutatorImports({ mutators: formUrlEncoded }); } + if (implementation.includes('NonReadonly<')) { + data += getOrvalGeneratedTypes(); + data += '\n'; + } + if (!output.schemas && needSchema) { data += generateModelsInline(builder.schemas); } diff --git a/packages/core/src/writers/split-mode.ts b/packages/core/src/writers/split-mode.ts index ff07073e0..e199832b2 100644 --- a/packages/core/src/writers/split-mode.ts +++ b/packages/core/src/writers/split-mode.ts @@ -8,6 +8,7 @@ import { upath, } from '../utils'; import { generateTarget } from './target'; +import { getOrvalGeneratedTypes } from './types'; export const writeSplitMode = async ({ builder, @@ -102,6 +103,10 @@ export const writeSplitMode = async ({ }); } + if (implementation.includes('NonReadonly<')) { + implementationData += getOrvalGeneratedTypes(); + } + implementationData += `\n${implementation}`; mswData += `\n${implementationMSW}`; diff --git a/packages/core/src/writers/split-tags-mode.ts b/packages/core/src/writers/split-tags-mode.ts index 72ee19284..5d08a3580 100644 --- a/packages/core/src/writers/split-tags-mode.ts +++ b/packages/core/src/writers/split-tags-mode.ts @@ -8,6 +8,7 @@ import { upath, } from '../utils'; import { generateTargetForTags } from './target-tags'; +import { getOrvalGeneratedTypes } from './types'; export const writeSplitTagsMode = async ({ builder, @@ -109,6 +110,11 @@ export const writeSplitTagsMode = async ({ }); } + if (implementation.includes('NonReadonly<')) { + implementationData += getOrvalGeneratedTypes(); + implementationData += '\n'; + } + implementationData += `\n${implementation}`; mswData += `\n${implementationMSW}`; diff --git a/packages/core/src/writers/tags-mode.ts b/packages/core/src/writers/tags-mode.ts index d327879ed..6e44269da 100644 --- a/packages/core/src/writers/tags-mode.ts +++ b/packages/core/src/writers/tags-mode.ts @@ -9,6 +9,7 @@ import { upath, } from '../utils'; import { generateTargetForTags } from './target-tags'; +import { getOrvalGeneratedTypes } from './types'; export const writeTagsMode = async ({ builder, @@ -104,6 +105,12 @@ export const writeTagsMode = async ({ } data += '\n\n'; + + if (implementation.includes('NonReadonly<')) { + data += getOrvalGeneratedTypes(); + data += '\n'; + } + data += implementation; if (output.mock) { diff --git a/packages/core/src/writers/types.ts b/packages/core/src/writers/types.ts index 0cb3ae0fb..5bf0be846 100644 --- a/packages/core/src/writers/types.ts +++ b/packages/core/src/writers/types.ts @@ -19,7 +19,7 @@ type UnionToIntersection = type DistributeReadOnlyOverUnions = T extends any ? NonReadonly : never; type Writable = Pick>; -export type NonReadonly = [T] extends [UnionToIntersection] ? { +type NonReadonly = [T] extends [UnionToIntersection] ? { [P in keyof Writable]: T[P] extends object ? NonReadonly> : T[P];