fix(openapi): preserve explicit null values in OpenAPI examples #11160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Refs: Request from Sarah Bawabe
Fixes a bug where explicit
nullvalues in OpenAPI response examples were being incorrectly replaced with schema example values. For example,balance_max: nullin a tiered rate structure (representing an unbounded upper tier) was being replaced with"100000000"from the schema's example field.Link to Devin run: https://app.devin.ai/sessions/dcba61f67aa34cc5aaac1eb92ee496a5
Requested by: Sarah Bawabe (@sbawabe)
Root Cause
The nullish coalescing operator (
??) was treating explicitnullvalues as nullish and falling back to schema examples. Changed to use explicitundefinedchecks to preservenullvalues in examples.Changes Made
propExampleFromParent ?? this.maybeResolveSchemaExample(property)to an explicit undefined check, so explicitnullvalues are preservedexample === nullin nullable schema handling, and changed property example resolution to useinExamplecheck to respect explicit presence in the example objectbalance-max-nullwith an OpenAPI spec containing:RateTierschema wherebalance_maxis nullablebalance_max: nulltiers[2].balance_maxisnull(not replaced with"100000000")Testing
Human Review Checklist
profileImageUrl: nullinstead of"profileImageUrl"(schema example)lastInsertRowidomitted when not present in the exampleexample === nullearly return in ExampleTypeFactory is correct for nullable schemas