diff --git a/packages/core/src/getters/array.ts b/packages/core/src/getters/array.ts index 582f734ed..21ff16754 100644 --- a/packages/core/src/getters/array.ts +++ b/packages/core/src/getters/array.ts @@ -61,7 +61,12 @@ export const getArray = ({ context, }); return { - value: `${schema.readOnly === true ? 'readonly ' : ''}${ + value: `${ + schema.readOnly === true && + !context.output.override.suppressReadonlyModifier + ? 'readonly ' + : '' + }${ resolvedObject.value.includes('|') ? `(${resolvedObject.value})[]` : `${resolvedObject.value}[]` diff --git a/packages/core/src/getters/object.ts b/packages/core/src/getters/object.ts index ea4d2cb73..0a38d6fcc 100644 --- a/packages/core/src/getters/object.ts +++ b/packages/core/src/getters/object.ts @@ -121,7 +121,9 @@ export const getObject = ({ acc.hasReadonlyProps ||= isReadOnly || false; acc.imports.push(...resolvedValue.imports); acc.value += `\n ${doc ? `${doc} ` : ''}${ - isReadOnly ? 'readonly ' : '' + isReadOnly && !context.output.override.suppressReadonlyModifier + ? 'readonly ' + : '' }${getKey(key)}${isRequired ? '' : '?'}: ${resolvedValue.value};`; acc.schemas.push(...resolvedValue.schemas); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index ef6ab041e..19b72eb70 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -112,6 +112,7 @@ export type NormalizedOverrideOutput = { useBigInt?: boolean; useNamedParameters?: boolean; useNativeEnums?: boolean; + suppressReadonlyModifier?: boolean; }; export type NormalizedMutator = { @@ -348,6 +349,7 @@ export type OverrideOutput = { useBigInt?: boolean; useNamedParameters?: boolean; useNativeEnums?: boolean; + suppressReadonlyModifier?: boolean; }; export type OverrideOutputContentType = { diff --git a/packages/orval/src/utils/options.ts b/packages/orval/src/utils/options.ts index 2b5cbaeff..fd0b4a253 100644 --- a/packages/orval/src/utils/options.ts +++ b/packages/orval/src/utils/options.ts @@ -248,6 +248,8 @@ export const normalizeOptions = async ( useDeprecatedOperations: outputOptions.override?.useDeprecatedOperations ?? true, useNativeEnums: outputOptions.override?.useNativeEnums ?? false, + suppressReadonlyModifier: + outputOptions.override?.suppressReadonlyModifier || false, }, allParamsOptional: outputOptions.allParamsOptional ?? false, urlEncodeParameters: outputOptions.urlEncodeParameters ?? false,