Skip to content

Conversation

@TristanSpeakEasy
Copy link
Member

Fix: Handle empty objects during marshaller sync for nullable schema upgrades

Problem

OpenAPI 3.0 to 3.1 document upgrades were panicking when processing schemas with nullable: true properties. The panic occurred in the marshaller's syncArraySlice function when it encountered nil nodes during array synchronization.

Root Cause

When nullable only schemas are upgraded from 3.0 to 3.1, they get converted to oneOf structures containing:

  1. An empty schema {}
  2. A null type schema {"type": ["null"]}

The issue was that completely empty schemas (after upgrade processing) were being synced to nil nodes instead of valid YAML mapping nodes, causing the array sync process to panic when processing the oneOf array.

Solution

Fixed the syncChanges function in marshaller/syncer.go to ensure that even empty structs produce valid YAML mapping nodes:

// Ensure we have a valid YAML node even for empty structs
if valueNode == nil {
    // Create an empty mapping node for empty structs
    valueNode = &yaml.Node{
        Kind:  yaml.MappingNode,
        Tag:   "!!map",
        Style: yaml.FlowStyle,
    }
}

Changes

  • marshaller/syncer.go: Added nil check and empty object node creation in syncChanges
  • openapi/upgrade.go: Removed debug logging
  • openapi/upgrade_test.go: Added test case for nullable schema upgrade
  • openapi/testdata/upgrade/: Added minimal test case and expected output

Testing

  • ✅ All existing tests pass
  • ✅ New test case covers the specific nullable schema scenario
  • ✅ Linting checks pass
  • ✅ Verified fix works for both minimal and complex upgrade scenarios

Impact

  • Fixes crash during OpenAPI document upgrades with nullable schemas
  • Maintains backward compatibility
  • Ensures proper conversion of nullable schemas to OpenAPI 3.1 format

…impacting docs upgrading with nullable only schemas
@TristanSpeakEasy TristanSpeakEasy added bug Something isn't working tests Test-related changes and improvements openapi Related to OpenAPI core functionality marshalling Related to data marshalling/unmarshalling labels Sep 11, 2025
@TristanSpeakEasy TristanSpeakEasy enabled auto-merge (squash) September 11, 2025 01:09
@TristanSpeakEasy TristanSpeakEasy merged commit 4b5b9fa into main Sep 11, 2025
10 checks passed
@TristanSpeakEasy TristanSpeakEasy deleted the fix/marshaller-empty-object-sync branch September 11, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working marshalling Related to data marshalling/unmarshalling openapi Related to OpenAPI core functionality tests Test-related changes and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants