Skip to content

Commit 4eb10c6

Browse files
committed
fix(core): reject duplicate mock generator types during normalization
Validates that each mock type (msw, faker) appears at most once in mock.generators. Duplicate entries would produce conflicting file outputs, so we fail fast with a clear error message. Also removes an unnecessary nullish coalescing on the required generators field (lint: @typescript-eslint/no-unnecessary-condition).
1 parent 08ac5cb commit 4eb10c6

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/orval/src/utils/options.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export async function normalizeOptions(
190190
} else if (mocksOption && typeof mocksOption === 'object') {
191191
mocks = {
192192
indexMockFiles: mocksOption.indexMockFiles ?? false,
193-
generators: (mocksOption.generators ?? []).map((m) =>
193+
generators: mocksOption.generators.map((m) =>
194194
isFunction(m)
195195
? m
196196
: ({
@@ -201,6 +201,17 @@ export async function normalizeOptions(
201201
};
202202
}
203203

204+
const seenMockTypes = new Set<string>();
205+
for (const entry of mocks.generators) {
206+
if (isFunction(entry)) continue;
207+
if (seenMockTypes.has(entry.type)) {
208+
throw new Error(
209+
`Duplicate mock generator type "${entry.type}". Each type can only appear once in mock.generators.`,
210+
);
211+
}
212+
seenMockTypes.add(entry.type);
213+
}
214+
204215
const defaultFileExtension = '.ts';
205216

206217
// `useQuery` / `useMutation` defaults are applied per-verb in

0 commit comments

Comments
 (0)