Skip to content

Commit

Permalink
feat: 'suppressReadonlyModifier' override option introduced (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
mironbalcerzak authored May 4, 2024
1 parent cffcc9a commit 86f2cf1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/getters/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}[]`
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/getters/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export type NormalizedOverrideOutput = {
useBigInt?: boolean;
useNamedParameters?: boolean;
useNativeEnums?: boolean;
suppressReadonlyModifier?: boolean;
};

export type NormalizedMutator = {
Expand Down Expand Up @@ -348,6 +349,7 @@ export type OverrideOutput = {
useBigInt?: boolean;
useNamedParameters?: boolean;
useNativeEnums?: boolean;
suppressReadonlyModifier?: boolean;
};

export type OverrideOutputContentType = {
Expand Down
2 changes: 2 additions & 0 deletions packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 86f2cf1

Please sign in to comment.