Skip to content

fix(core): keep nested required object defaults in their parent - #1251

Merged
erunion merged 2 commits into
readmeio:mainfrom
theluckystrike:fix/nested-required-object-defaults
Nov 12, 2026
Merged

erunion merged 2 commits into
readmeio:mainfrom
theluckystrike:fix/nested-required-object-defaults

Conversation

@theluckystrike

Copy link
Copy Markdown
Contributor

Fixes #1200.

getJSONSchemaDefaults seeded an empty object for every required object property at the root of the defaults, whatever its depth. The walk to a nested destination also fell back to a throwaway object, so a default set below the first level was lost. With the issue's schema the body went out as customer, reference and an extra top-level address, and an API with additionalProperties false rejected every such request.

The parent is now resolved first, from the parent pointer the function already reads. A required object is seeded inside its parent, a default is written into its parent, and when the parent is not in the defaults (it is optional, or sits inside an array) the value is left out instead of landing at the root.

Two new tests in getJSONSchemaDefaults.test.ts use the issue's order schema. One checks that customer.address is seeded inside customer and keeps a nested default, and the other that a required child of an optional parent adds nothing. Both fail on main (the first gets address at the root and loses the default) and pass with this change. All 85 core tests pass, and tsc, oxlint and oxfmt are clean on both files.

getJSONSchemaDefaults seeded an empty object for every required
object property at the root of the payload, whatever its depth, and
the walk to a nested destination fell back to a throwaway object. A
required object below the root was sent as an extra top-level key, so
an API with additionalProperties false rejected the request, and a
default set below the first level was lost (issue 1200).

The parent is now resolved first. Required objects are seeded inside
it, defaults are written into it, and when the parent is not in the
defaults (an optional parent) the value is left out instead of being
written at the root.

Fixes readmeio#1200
@changeset-bot

changeset-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3405ddf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@readme/api-core Patch
api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@theluckystrike theluckystrike changed the title Keep nested required object defaults in their parent fix(core): keep nested required object defaults in their parent Nov 8, 2026
@erunion
erunion merged commit 314c142 into readmeio:main Nov 12, 2026
8 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.

Nested required object properties are seeded as top-level keys in the request body

2 participants