You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mock): emit bare factory call for primitive-union $ref in additionalProperties (#3200) (#3504)
* fix(mock): emit bare factory call for primitive-union $ref in additionalProperties (#3200)
When `schemas: true` emits per-schema faker factories, an `additionalProperties`
dictionary whose value is a $ref to a primitive `oneOf`/`anyOf` (e.g. `number |
string`) delegated to `get<X>Mock()` but wrapped the call in `{ ...get<X>Mock()
}`. The factory returns a primitive union, which is not spreadable: the output
failed to compile (TS2698) and would discard the value as `{}` at runtime.
The delegation now treats a `oneOf`/`anyOf` as object-like only when every
branch resolves to an object, so primitive unions emit the bare `get<X>Mock()`
call while object compositions keep the spread form.
Closes#3200
* fix(mock): isolate $ref cycle guard per branch in object-likeness check (#3200)
Addresses review feedback on the additionalProperties dictionary fix:
- The cycle-guard `Set` was shared and mutated across all `oneOf`/`anyOf`
branches, so the first branch could poison its siblings: a composition like
`oneOf: [{$ref: Foo}, {$ref: Foo}]` made the second branch look cyclic and
return `false`, misclassifying an object-only union as non-object-like. The
guard now takes a fresh copy at each `$ref` hop, so siblings sharing a `$ref`
no longer trip it.
- Rename `compositionResolvesToObject` -> `resolvesToObjectLike`; it also
recognizes plain object schemas (`properties`/`additionalProperties`/`allOf`),
not just compositions.
- Return early when a `$ref` is not a string instead of using an `''` fallback
key, and initialize `resolved` via an explicit if/else for clarity.
- Make the regression assertions whitespace-tolerant and detect a spread
regardless of brace formatting.
---------
Co-authored-by: Melloware <mellowaredev@gmail.com>
0 commit comments