Skip to content

fix(mock): strict faker schema mock types for enums, nested spreads, and binary - #3607

Merged
melloware merged 14 commits into
orval-labs:masterfrom
Hypenate:fix/3590-strict-faker-schema-mock-types
Jun 17, 2026
Merged

fix(mock): strict faker schema mock types for enums, nested spreads, and binary#3607
melloware merged 14 commits into
orval-labs:masterfrom
Hypenate:fix/3590-strict-faker-schema-mock-types

Conversation

@Hypenate

@Hypenate Hypenate commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Emit schema-aware strict {Schema}Mock aliases: mapped types for objects, type aliases for enums/scalars/arrays, and ArrayBuffer for binary faker schema mocks
  • Cast nested get*Mock() spreads to base mock types so MockWithNullableOverrides parent casts typecheck
  • Collect inline split-factory schema names for missing mock type declarations in schemas/index.faker.ts
  • Add petstore regression spec tests/specifications/issue-3590.yaml (follows issue-3525.yaml style)

Fixes #3590

Supersedes #3591 (closed when the head fork was deleted and recreated).

Test plan

  • packages/mock unit tests (247 pass)
  • tests/generated/mock typecheck passes (node tests/scripts/typecheck-generated.mjs)
  • Snapshot test mock issue-3590 strict faker schema mocks typecheck and emit correct aliases

Made with Cursor

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced strict mock type system with automatic schema kind classification (object, alias, binary) for more accurate mock declarations.
    • Improved schema factory import recovery to reduce redundant imports in generated mock code.
  • Bug Fixes

    • Fixed duplicate imports in complex schema scenarios with wide parent-child relationships.
    • Fixed import generation for binary response types.
    • Fixed circular reference handling in strict mock generation.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 45a5c079-d707-49e2-a527-6a5fc9862fe6

📥 Commits

Reviewing files that changed from the base of the PR and between 4b023fc and 69c83bb.

📒 Files selected for processing (3)
  • packages/mock/src/msw/mocks.test.ts
  • packages/mock/src/msw/mocks.ts
  • tests/configs/mock.config.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/configs/mock.config.ts
  • packages/mock/src/msw/mocks.ts
  • packages/mock/src/msw/mocks.test.ts

📝 Walkthrough

Walkthrough

Fixes three TypeScript errors in strict faker schema mock generation (issue #3590): enum *Mock types now emit direct aliases instead of broken mapped types, binary schemas emit ArrayBuffer aliases, and import duplication from shared-array spread is prevented via indexed delta helpers. A new StrictMockSchemaKind classification is propagated through all mock output aggregation and writer paths.

Changes

Strict mock schema kind tracking, import dedup, and enum/binary type fixes (issue #3590)

Layer / File(s) Summary
StrictMockSchemaKind core type contracts
packages/core/src/types.ts
Adds StrictMockSchemaKind = 'object' | 'alias' | 'binary' union and optional strictMockSchemaKinds record to GeneratorMockOutput, GeneratorMockOutputFull, ClientMockGeneratorBuilder, and FinalizeMockImplementationOptions.
Import-delta accumulation helpers
packages/mock/src/faker/imports.ts, packages/mock/src/faker/imports.test.ts
Adds appendImportsDelta (indexed push from offset), mergeReturnedMockImports (length-guarded conditional merge), and collectSplitMockTypeImports (regex-based split mock type scan) with tests covering non-duplication behavior for issue #3590.
Schema kind classification and kind-aware mock type declarations
packages/mock/src/mock-types.ts, packages/mock/src/mock-types.test.ts
Adds classifyStrictMockSchemaType, updates getStrictMockTypeDeclaration/getStrictMockTypeDeclarations to emit direct alias or ArrayBuffer for non-object kinds, adds getStrictMockSchemaKindsFromResponses and mergeStrictMockSchemaKinds, threads kinds through buildStrictMockTypeFileHeader and dedupeStrictMockTypeDeclarations.
Faker getter import dedup fixes
packages/mock/src/faker/getters/object.ts, packages/mock/src/faker/getters/object.test.ts, packages/mock/src/faker/getters/array-item-factory.ts, packages/mock/src/faker/resolvers/value.ts
Refactors getMockObject to use mergeReturnedMockImports instead of direct push; adds strict mock as-cast in array-item factory; updates resolveMockValue to attach type-only strict mock import and conditional as <StrictType> cast for object-like $ref delegations, consolidating all import merges via mergeReturnedMockImports.
generateFakerForSchemas kind tracking and recursion guards
packages/mock/src/faker/index.ts, packages/mock/src/faker/index.test.ts
Updates generateFakerForSchemas to accumulate strictMockSchemaKinds via classifyStrictMockSchemaType, seeds existingReferencedAllOfRefs to guard cyclic allOf schemas, switches to appendImportsDelta, filters locally generated type symbols from imports, and returns strictMockSchemaKinds in GenerateFakerForSchemasResult. Adds mutual and multi-hop allOf cycle tests.
MSW import-delta fixes and strictMockSchemaKinds emission
packages/mock/src/msw/mocks.ts, packages/mock/src/msw/mocks.test.ts, packages/mock/src/msw/index.ts
Refactors getResponsesMockDefinition to use appendImportsDelta with per-response baseline; extends generateDefinition to compute strictMockSchemaKinds from response and implementation kinds; aggregates and returns strictMockSchemaKinds from generateMSW. Adds test for undefined response.imports case.
Schema-factory import recovery and filterLocalStrictMockTypeImports
packages/core/src/writers/mock-imports.ts, packages/core/src/writers/mock-imports.test.ts, packages/core/src/writers/finalize-mock-implementation.ts
Introduces mock-imports.ts with KnownSchemaFactoryImportSets, buildKnownSchemaFactoryImportSets, collectSchemaFactoryImportsFromImplementation, mergeGeneratorImports, and collectRecoveredSchemaFactoryImports; adds filterLocalStrictMockTypeImports and strictMockSchemaKinds aggregation to finalize-mock-implementation.ts.
strictMockSchemaKinds propagation through target and target-tags
packages/core/src/writers/target.ts, packages/core/src/writers/target-tags.ts
Updates emptyMockOutputFull, generateTarget, flattenMockOutput, mergeOperationMockOutputs, initialMockOutputsForOperation, and per-tag handler wrapping to copy and merge strictMockSchemaKinds at each aggregation point.
Mode writers: finalize options, recovered imports, filtered imports
packages/core/src/writers/single-mode.ts, packages/core/src/writers/split-mode.ts, packages/core/src/writers/tags-mode.ts, packages/core/src/writers/split-tags-mode.ts, packages/orval/src/client.ts, packages/orval/src/write-specs.ts
Updates all four write modes to compute finalizeMockOptions per mock, collect recovered schema-factory imports when FAKER+schemas is active, merge and filter via filterLocalStrictMockTypeImports; wires strictMockSchemaKinds through generateOperations and writeFakerSchemaMocks.
Regression fixtures, configs, and integration tests
tests/specifications/issue-3590*.yaml, tests/configs/mock.config.ts, tests/api-generation.spec.ts
Adds four OpenAPI YAML fixtures, four Orval config entries, and four integration tests asserting alias type emission, no import overflow, tags-split schema factory import consolidation, and binary response generation without response.imports.

Sequence Diagram(s)

sequenceDiagram
  participant generateFakerForSchemas
  participant getMockScalar
  participant classifyStrictMockSchemaType
  participant appendImportsDelta
  participant mergeStrictMockSchemaKinds

  generateFakerForSchemas->>getMockScalar: resolve schema (with seeded allOf refs)
  getMockScalar-->>generateFakerForSchemas: implementation + imports
  generateFakerForSchemas->>appendImportsDelta: append new imports since last snapshot
  generateFakerForSchemas->>classifyStrictMockSchemaType: classify schema as object/alias/binary
  classifyStrictMockSchemaType-->>generateFakerForSchemas: StrictMockSchemaKind
  generateFakerForSchemas->>generateFakerForSchemas: accumulate strictMockSchemaKinds[typeName]
  generateFakerForSchemas->>mergeStrictMockSchemaKinds: merge accumulated kinds
  mergeStrictMockSchemaKinds-->>generateFakerForSchemas: merged Record<string, StrictMockSchemaKind>
  generateFakerForSchemas-->>writeFakerSchemaMocks: implementation + strictMockSchemaKinds
Loading
sequenceDiagram
  participant WriteModeWriter as writeSplitMode / writeSplitTagsMode / writeTagsMode
  participant getFinalizeMockImplementationOptions
  participant collectRecoveredSchemaFactoryImports
  participant mergeGeneratorImports
  participant filterLocalStrictMockTypeImports
  participant generateImportsForBuilder

  WriteModeWriter->>getFinalizeMockImplementationOptions: mockOutput[]
  getFinalizeMockImplementationOptions-->>WriteModeWriter: finalizeMockOptions (strictSchemaTypeNames, strictMockSchemaKinds)
  WriteModeWriter->>collectRecoveredSchemaFactoryImports: finalizedImplementation + componentSchemaNames
  collectRecoveredSchemaFactoryImports-->>WriteModeWriter: recoveredSchemaFactoryImports[]
  WriteModeWriter->>mergeGeneratorImports: mockOutput.imports + recoveredSchemaFactoryImports
  mergeGeneratorImports-->>WriteModeWriter: merged imports[]
  WriteModeWriter->>filterLocalStrictMockTypeImports: merged imports + strictSchemaTypeNames
  filterLocalStrictMockTypeImports-->>WriteModeWriter: filtered imports[]
  WriteModeWriter->>generateImportsForBuilder: filtered imports
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • orval-labs/orval#3575: Modifies target-tags.ts to preserve strictMockSchemaTypeNames through per-tag mock output aggregation — the main PR extends the same propagation pattern to also carry strictMockSchemaKinds.
  • orval-labs/orval#3543: Modifies mock-types.ts and dedupeStrictMockTypeDeclarations / buildStrictMockTypeFileHeader to emit strict mock type declarations — the main PR extends these same functions to accept and use the kinds mapping.
  • orval-labs/orval#3614: Modifies resolveMockValue's $ref delegation path to change how schema-factory GeneratorImports are produced and merged — the main PR extends this same code path to add strict-mock type casting and mergeReturnedMockImports.

Poem

🐇 Hoppity hop, the schemas align,
No more {} where enums should shine!
Delta imports hop in, one by one,
ArrayBuffer mocks — the fix is done.
Strict kinds of alias, object, binary,
The rabbit stamps this PR: extraordinary! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main changes: fixing strict faker schema mock types for enums, nested spreads, and binary types.
Linked Issues check ✅ Passed The PR addresses all three bugs documented in #3590: enum Mock types now use aliases, nested spreads are properly cast to base mock types, and binary types correctly use ArrayBuffer.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the three documented bugs in #3590: type definitions, import merging, schema kind classification, and test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Hypenate and others added 9 commits June 15, 2026 08:59
…and binary

Classify strict {Schema}Mock aliases by schema shape.

Cast nested factory spreads to base mock types.

Add petstore regression spec for #3590.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Import {Schema}Mock from index.faker when operation fakers spread schema
factories with strict casts. Skip imports that duplicate local response mocks.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ports (#3590)

Use appendImportsDelta to avoid stack overflows with schemas: true.

Recover missing get*Mock imports in tags-split faker files.

Guard MSW generation when response.imports is undefined.

Add pet-themed regression specs and tests for each failure mode.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use OpenApiSchemaObject and createTestContextSpec override options.

Cast undefined response imports via unknown for the runtime guard test.

Co-authored-by: Cursor <cursoragent@cursor.com>
)

Merge returned mock imports only when the shared array was not mutated in place.

Propagate oneOf split helper types into shared import aggregation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Merge getMockScalar result imports in generateFakerForSchemas.

Collect nested oneOf split helper types and filter local strict mock imports in single mode.

Co-authored-by: Cursor <cursoragent@cursor.com>
PetDetailSettingsItem is referenced by strict mock factories and must be imported in index.faker.ts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Hypenate
Hypenate force-pushed the fix/3590-strict-faker-schema-mock-types branch from 09a69d0 to f1dbbe2 Compare June 15, 2026 07:00
@Hypenate

Copy link
Copy Markdown
Contributor Author

I'm going for a full AI approach here...

I'll let it make a local build of Orval and check again against all our yaml files.
I'll let it itterate over this processes until all our errors are gone.

I'm not sure how we'll do the review process here...
I'll wait a bit for what it spits out.

@wadakatu what do you think?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
packages/mock/src/faker/imports.test.ts (1)

67-79: ⚡ Quick win

Add a strict-signature fixture for collectSplitMockTypeImports.

Current coverage validates only the non-strict signature form. Please add one strict generic factory case (<O extends Partial<T>...>(overrideResponse?: O): MockWithNullableOverrides<...>) to lock in strict-mode import recovery behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mock/src/faker/imports.test.ts` around lines 67 - 79, The test suite
for collectSplitMockTypeImports currently only validates the non-strict
signature form. Add an additional test case (another it() block within the
describe('collectSplitMockTypeImports') block) that covers the strict generic
factory signature pattern. This new test should create an implementation string
using the strict-signature form with a generic type parameter constraint (like
<O extends Partial<T>), an optional overrideResponse parameter, and a return
type using MockWithNullableOverrides, then verify that
collectSplitMockTypeImports correctly extracts all necessary type imports from
this pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/writers/split-mode.ts`:
- Around line 17-22: The merged imports are being emitted directly after
recovery without filtering for local strict mock types, which allows split mock
files to import Schema Mock types declared locally, causing duplicate identifier
errors. Find where the merged imports from mergeGeneratorImports are emitted
around line 239-246 and apply the filterLocalStrictMockTypeImports function to
filter out locally declared strict mock types before emitting the split mock
imports, ensuring that only safe imports are included in the output.

In `@packages/core/src/writers/tags-mode.ts`:
- Around line 336-348: The usesSchemaFactories check on line 336 is evaluating
all generators in output.mock.generators globally, causing schema-factory
recovery to execute for unrelated mock entries in the same loop when names
collide. Scope this check to only the current mock entry being processed by
restricting the generator check to generators that are specific to the current
output or mock entry context, rather than checking all generators in the output
collection. This ensures that collectRecoveredSchemaFactoryImports is only
called when the specific mock entry being processed actually uses faker with
schemas enabled, preventing spurious imports in unrelated mock files.

In `@packages/mock/src/faker/imports.ts`:
- Around line 42-44: The regex pattern in the matchAll call only matches factory
signatures that use Partial types for the overrideResponse parameter, but strict
factories use generic signatures and are being skipped, resulting in missing
type imports. Update the regex pattern to handle both non-strict Partial type
signatures and strict generic signatures. The pattern should be made more
flexible to capture factory signatures regardless of whether they use Partial or
generic type constraints on the override parameter.

In `@packages/mock/src/mock-types.ts`:
- Around line 53-60: The condition that checks for schema.oneOf, schema.anyOf,
and schema.allOf in the type classification logic unconditionally treats all
composed schemas as object-kind. For scalar unions that compose scalar types
rather than objects, this misclassification causes them to be routed
incorrectly. Instead of unconditionally including these composition keywords in
the object-kind check, add logic to inspect the schemas within the composition
arrays (the items in oneOf, anyOf, or allOf) to determine whether they actually
compose objects or just scalars, and only classify them as object-kind when they
genuinely compose object types.

In `@packages/mock/src/msw/mocks.test.ts`:
- Line 8: The regression test for aggregating imports when response.imports is
undefined has a tautological assertion at line 31 that always passes
(toBeGreaterThanOrEqual(0)). Replace this weak assertion with an explicit check
that validates the intended behavior of aggregating imports—verify that the
actual aggregated imports match the expected aggregated imports from the test
case, ensuring the test will properly catch regressions in the undefined-import
handling logic.

---

Nitpick comments:
In `@packages/mock/src/faker/imports.test.ts`:
- Around line 67-79: The test suite for collectSplitMockTypeImports currently
only validates the non-strict signature form. Add an additional test case
(another it() block within the describe('collectSplitMockTypeImports') block)
that covers the strict generic factory signature pattern. This new test should
create an implementation string using the strict-signature form with a generic
type parameter constraint (like <O extends Partial<T>), an optional
overrideResponse parameter, and a return type using MockWithNullableOverrides,
then verify that collectSplitMockTypeImports correctly extracts all necessary
type imports from this pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: af6ce46e-662c-4c0a-a850-f1dfb9b587f4

📥 Commits

Reviewing files that changed from the base of the PR and between 89e0de8 and f1dbbe2.

⛔ Files ignored due to path filters (66)
  • tests/__snapshots__/mock/issue-3525-multi/endpoints.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3525/model/index.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split-fetch/pets/pets/pets.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split-fetch/pets/pets/pets.msw.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split-multi-fetch/store/store/store.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split-multi-fetch/store/store/store.msw.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split/pets/pets/pets.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3574-strict-mock-tags-split/pets/pets/pets.msw.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-binary-response-imports/endpoints.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-binary-response-imports/model/index.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/pets/pets/pets.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/pets/pets/pets.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/healthStatus.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/index.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/index.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/pet.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/petDetailResponse.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/petOwner.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-tags-split-schema-imports/schemas/responseBase.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/endpoints.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child0.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child1.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child10.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child11.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child12.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child13.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child14.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child15.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child16.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child17.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child18.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child19.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child2.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child20.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child21.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child22.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child23.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child24.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child25.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child26.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child27.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child28.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child29.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child3.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child4.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child5.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child6.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child7.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child8.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/child9.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/index.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/index.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590-wide-schema-imports/model/wideParent.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/endpoints.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/index.faker.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/index.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/pet.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petCategory.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petDetail.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petDetailSettingsItem.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petList.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petProfile.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/petSetting.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/photoUpload.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/score.ts is excluded by !**/__snapshots__/**
  • tests/__snapshots__/mock/issue-3590/model/status.ts is excluded by !**/__snapshots__/**
📒 Files selected for processing (32)
  • packages/core/src/types.ts
  • packages/core/src/writers/finalize-mock-implementation.ts
  • packages/core/src/writers/mock-imports.test.ts
  • packages/core/src/writers/mock-imports.ts
  • packages/core/src/writers/single-mode.ts
  • packages/core/src/writers/split-mode.ts
  • packages/core/src/writers/split-tags-mode.ts
  • packages/core/src/writers/tags-mode.ts
  • packages/core/src/writers/target-tags.ts
  • packages/core/src/writers/target.ts
  • packages/mock/src/faker/getters/array-item-factory.ts
  • packages/mock/src/faker/getters/combine.ts
  • packages/mock/src/faker/getters/object.test.ts
  • packages/mock/src/faker/getters/object.ts
  • packages/mock/src/faker/imports.test.ts
  • packages/mock/src/faker/imports.ts
  • packages/mock/src/faker/index.test.ts
  • packages/mock/src/faker/index.ts
  • packages/mock/src/faker/resolvers/value.ts
  • packages/mock/src/mock-types.test.ts
  • packages/mock/src/mock-types.ts
  • packages/mock/src/msw/index.ts
  • packages/mock/src/msw/mocks.test.ts
  • packages/mock/src/msw/mocks.ts
  • packages/orval/src/client.ts
  • packages/orval/src/write-specs.ts
  • tests/api-generation.spec.ts
  • tests/configs/mock.config.ts
  • tests/specifications/issue-3590-binary-response-imports.yaml
  • tests/specifications/issue-3590-tags-split-schema-imports.yaml
  • tests/specifications/issue-3590-wide-schema-imports.yaml
  • tests/specifications/issue-3590.yaml

Comment thread packages/core/src/writers/split-mode.ts Outdated
Comment thread packages/core/src/writers/tags-mode.ts Outdated
Comment thread packages/mock/src/faker/imports.ts
Comment thread packages/mock/src/mock-types.ts
Comment thread packages/mock/src/msw/mocks.test.ts
@melloware melloware added the mock Related to mock generation label Jun 15, 2026
…#3590)

Filter local strict mock type imports in split mode.

Scope schema-factory recovery to the current mock generator.

Recognize strict factory signatures when collecting split imports.

Classify scalar composed schemas as aliases.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/mock/src/mock-types.ts`:
- Around line 71-72: The `branch` parameter in the callback function passed to
`branches.some()` is missing an explicit type annotation, which causes
TypeScript to infer it as `any` and triggers a strict type checking error. Add
an explicit type annotation to the `branch` parameter in the callback to
indicate it should be typed as `SchemaObject | ReferenceObject` (the union type
of items that can appear in `oneOf`, `anyOf`, and `allOf` arrays according to
the OpenAPI specification). This will satisfy the strict TypeScript checks and
eliminate the implicit `any` type warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fdca5b8d-1403-48c7-91b1-ff86d976eda3

📥 Commits

Reviewing files that changed from the base of the PR and between f1dbbe2 and 432c35c.

📒 Files selected for processing (8)
  • packages/core/src/writers/split-mode.ts
  • packages/core/src/writers/split-tags-mode.ts
  • packages/core/src/writers/tags-mode.ts
  • packages/mock/src/faker/imports.test.ts
  • packages/mock/src/faker/imports.ts
  • packages/mock/src/mock-types.test.ts
  • packages/mock/src/mock-types.ts
  • packages/mock/src/msw/mocks.test.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/mock/src/msw/mocks.test.ts
  • packages/mock/src/faker/imports.test.ts
  • packages/core/src/writers/split-mode.ts
  • packages/core/src/writers/tags-mode.ts
  • packages/mock/src/mock-types.test.ts
  • packages/mock/src/faker/imports.ts
  • packages/core/src/writers/split-tags-mode.ts

Comment thread packages/mock/src/mock-types.ts
Cast oneOf/anyOf/allOf branches so the branch callback is not implicit any.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Hypenate

Copy link
Copy Markdown
Contributor Author

@melloware @wadakatu

I've fixed the CodeRabbit suggestions.
How do we continue?

@melloware

Copy link
Copy Markdown
Collaborator

i will let @wadakatu review

@wadakatu

wadakatu commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Reviewed on @melloware's cc. Built locally — all gates green (build / typecheck / lint / format, unit 0-fail, snapshots 5056, typecheck-generated mock client). All three #3590 bugs are fixed in the actual output: enum → self-alias (StatusMock = Status), nested spread → { ...(getPetMock() as PetMock) }, binary → ArrayBuffer.

I also stress-tested against master with an adversarial spec ($ref-alias-to-enum, record maps, allOf+enum, enum arrays, deep nesting, nullable objects/fields) under schemas: true + strict: master = 3 tsc errors, this branch = 1, no new regressions. It fixes more than the documented cases — e.g. allOf with an enum prop and the cascading parent MockWithNullableOverrides cast both compile now.

LGTM. Non-blocking notes in a follow-up comment below.

@wadakatu

Copy link
Copy Markdown
Contributor

Non-blocking notes (none should hold up merge):

Pre-existing gap (not this PR). A schema that is itself a nullable object (type: object + nullable: true) still fails: getXMock(): XMock can return null but the mapped type excludes it. master fails identically, so not a regression — but it's in this same strict-faker area, so maybe worth a follow-up issue. (Field-level nullable is fine — nonNullable strips it.)

Minor. getStrictMockSchemaKindsFromResponses classifies every type-import off the single top-level response.originalSchema, so a non-object imported alongside an object (e.g. inline oneOf: [Object, Enum]) gets object. I couldn't make it fail (endpoint files only declare strict types for object responses), just latent. Relatedly, a pure $ref-alias-to-enum is classified object → emits a mapped type instead of an alias; compiles today via a keyof coincidence, but resolving the ref target would be cleaner.

Hypenate and others added 2 commits June 17, 2026 08:53
…er-schema-mock-types

Co-authored-by: Cursor <cursoragent@cursor.com>
)

Push resolved imports from resolveMockValue into combineImports instead of

scraping the shared imports array, which #3606 no longer mutates.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Hypenate

Copy link
Copy Markdown
Contributor Author

@melloware I've fixed the merge conflicts.
If ok with you, I'll do a follow-up PR from the issues that @wadakatu mentioned.

melloware
melloware previously approved these changes Jun 17, 2026
@melloware

Copy link
Copy Markdown
Collaborator

Sorry just created another merge conflict :)

…er-schema-mock-types

Co-authored-by: Cursor <cursoragent@cursor.com>
@melloware
melloware merged commit 66af3e2 into orval-labs:master Jun 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mock Related to mock generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict faker mocks (required+nonNullable): enum *Mock types, nested spreads, and Blob/ArrayBuffer mismatch

3 participants