Skip to content

fix(mock): invoke override.mock.properties functions in faker schema factories - #3585

Merged
melloware merged 2 commits into
orval-labs:masterfrom
Hypenate:fix/faker-schema-factory-property-overrides
Jun 11, 2026
Merged

fix(mock): invoke override.mock.properties functions in faker schema factories#3585
melloware merged 2 commits into
orval-labs:masterfrom
Hypenate:fix/faker-schema-factory-property-overrides

Conversation

@Hypenate

@Hypenate Hypenate commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix faker schema factory generation (schemas: true) so override.mock.properties function values are serialized as IIFEs, matching operation response mocks
  • Reuse getMockWithoutFunc in generateFakerForSchemas instead of passing raw override.mock options
  • Add regression tests for IIFE emission and default faker fallback on non-overridden properties

Closes #3584

Test plan

  • npx vitest run packages/mock — 242 tests passing
  • New unit tests in packages/mock/src/faker/index.test.ts verify overridden properties emit (() => ...)() and not raw () => ... arrow functions

Summary by CodeRabbit

  • Tests

    • Added tests verifying mock schema generation respects override property functions (serialized as immediately-invoked expressions) while leaving non-overridden properties using default fake data.
  • Refactor

    • Updated mock option processing to serialize override functions in generated schema factories.
    • Exported an internal utility to improve modularity and reuse across modules.

…factories

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

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eadc8ad2-0b2e-40d1-91a4-168a59663bd1

📥 Commits

Reviewing files that changed from the base of the PR and between 04ceee2 and df1e898.

📒 Files selected for processing (1)
  • packages/mock/src/faker/index.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/mock/src/faker/index.test.ts

📝 Walkthrough

Walkthrough

Exported getMockWithoutFunc from MSW mocks, used it in generateFakerForSchemas to serialize override.mock.properties functions as IIFEs, and added Vitest tests asserting IIFE emission for overridden schema properties and default faker output for non-overridden properties.

Changes

Schema faker function override serialization

Layer / File(s) Summary
Export helper and integrate into faker schema generation
packages/mock/src/msw/mocks.ts, packages/mock/src/faker/index.ts
getMockWithoutFunc is exported from the MSW mocks module. generateFakerForSchemas imports and uses it to compute mockOptions via getMockWithoutFunc(context.spec, context.output.override), causing override.mock.properties functions to be serialized as IIFE expressions rather than left as raw function references.
Test coverage for override property serialization
packages/mock/src/faker/index.test.ts
New Vitest suite verifies overridden schema properties (id, created, archiveDuration) are emitted as IIFEs and do not appear as arrow-function forms, and that non-overridden properties (e.g., name) still use default faker generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • orval-labs/orval#3084: Related refactor of mock-generation helpers and IIFE-based override serialization used by this change.
  • orval-labs/orval#3407: Prior adjustments to MSW/Faker mock generator pipeline that touch related code paths.

Suggested labels

mock

Suggested reviewers

  • wadakatu
  • melloware

Poem

🐰 I found a hidden helper in a code-filled glade,
I exported it neat so overrides are played,
Functions now call as soon as they're born,
Schemas mock right from dusk until morn,
Tests clap their paws — the rabbits are glad! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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 describes the primary change: invoking override.mock.properties functions in faker schema factories, which directly matches the main fix implemented across the three modified files.
Linked Issues check ✅ Passed The PR directly addresses all acceptance criteria from issue #3584: exports getMockWithoutFunc, updates generateFakerForSchemas to use it for IIFE serialization, adds regression tests verifying correct types and IIFE emission for overridden properties, and preserves default faker generation for non-overridden properties.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: test addition verifies IIFE behavior, getMockWithoutFunc export enables the fix, and generateFakerForSchemas integration implements the solution. No extraneous changes detected.

✏️ 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.

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

Copy link
Copy Markdown
Contributor Author

@wadakatu FYI 🤏🏻

@melloware
melloware merged commit f0028b6 into orval-labs:master Jun 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(mock): invoke override.mock.properties functions in faker schema factories (schemas: true)

2 participants