Skip to content

feat: support context-aware empty value preservation#173

Merged
erunion merged 3 commits into
mainfrom
hugo/cx-1601-cant-send-empty-data-arrayobject-in-try-it
May 26, 2026
Merged

feat: support context-aware empty value preservation#173
erunion merged 3 commits into
mainfrom
hugo/cx-1601-cant-send-empty-data-arrayobject-in-try-it

Conversation

@HugoHSun
Copy link
Copy Markdown
Contributor

@HugoHSun HugoHSun commented May 26, 2026

🚥 Resolves CX-1601

🧰 Changes

API Explorer uses empty objects as placeholders for object-shaped array items while the form is being edited. Those placeholders are useful in the UI, but they should not be sent as real values in the request payload.

The first pass added a dedicated option for empty objects inside arrays, but that made the package API more specific than it needed to be. This keeps the existing preserveEmptyObject and preserveEmptyArray options, and lets them accept a context map for root, objectProperty, and arrayItem. Existing boolean usage still works, while callers that need more control can choose exactly where empty values should be preserved.

For API Explorer, this means we can preserve intentional empty object properties while still filtering empty object array-item placeholders out of the payload.

🧬 QA & Testing

Added coverage for context-aware empty object and empty array preservation, including the case where both option maps are used together.

@HugoHSun HugoHSun marked this pull request as ready for review May 26, 2026 10:51
@HugoHSun HugoHSun requested a review from erunion as a code owner May 26, 2026 10:51
@HugoHSun HugoHSun requested a review from darrenyong May 26, 2026 10:51
Comment thread src/index.ts
Comment on lines +24 to +31
function shouldPreserve(rule: PreservationRule | undefined, context: PreservationContext) {
if (typeof rule === 'boolean') {
return rule;
}

return rule?.[context] ?? false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should we add an early return for a falsy value of rule just to make it a little more clear?

Suggested change
function shouldPreserve(rule: PreservationRule | undefined, context: PreservationContext) {
if (typeof rule === 'boolean') {
return rule;
}
return rule?.[context] ?? false;
}
function shouldPreserve(rule: PreservationRule | undefined, context: PreservationContext) {
if (!rule) return false;
if (typeof rule === 'boolean') {
return rule;
}
return rule?.[context];
}

@erunion erunion merged commit f0c08e0 into main May 26, 2026
5 checks passed
@erunion erunion deleted the hugo/cx-1601-cant-send-empty-data-arrayobject-in-try-it branch May 26, 2026 22:07
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.

3 participants