Skip to content

Conversation

@alexpmule
Copy link
Contributor

  • Added support for rendering nullable types as "Type or null" in the API documentation.
  • Introduced new tests to validate the rendering of nullable types, including scalar and complex types.
  • Updated the logic in the PropertyDocumentMixin to correctly identify and handle nullable unions.
  • Enhanced the UI to ensure that nullable types do not display union selectors, improving clarity for users.

Improve nullable types rendering in OpenAPI 3.0 specs

🎯 Problem

When a field has nullable: true in OpenAPI 3.0 specs, AMF converts it to a union type (base type + null). The component was rendering all nullable types as "Union" with an "Any of" selector, which created a confusing and verbose UX, especially for simple nullable fields.

This affected all nullable types:

  • ✅ Scalars (string, integer, boolean, etc.)
  • ✅ Arrays
  • ✅ Objects

Example:
A simple timezone field with type: string and nullable: true was showing:

Type: Union
Any of: [TZ] [NULL]  ← Required click to understand it's just "string or null"

💡 Solution

Implemented intelligent nullable detection that simplifies the rendering:

Key Changes:

  1. Smart Nullable Detection (_checkNullableUnion)

    • Detects when a UnionShape has exactly 2 members where one is NilShape
    • Works for all types: scalars, arrays, and objects
  2. Simplified Rendering

    • Nullable scalars → "String or null", "Integer or null", etc.
    • Nullable arrays → "Array or null" (with Show/Hide to view items)
    • Nullable objects → "Object or null" (with Show/Hide to view properties)
    • Real unions (e.g., string | number) → Keep full Union selector ✅
  3. Enhanced Type Detection

    • Updated _computeIsObject() and _computeIsArray() to detect base types in nullable unions
    • Updated _computeIsUnion() to exclude nullable unions from being treated as full unions
    • Complex nullable types properly expand to show their internal structure

Visual Result:

Before:

timezone
  Type: Union           ← Confusing
  Any of: [TZ] [NULL]   ← Extra clicks needed

After:

timezone
  Type: String or null  ← Clear and direct!

For complex types:

metadata                [HIDE]
  Type: Object or null  ← Clear
  
  [When expanded:]
    source: String
    timestamp: DateTime

alexpmule and others added 2 commits January 2, 2026 11:46
- Added support for rendering nullable types as "Type or null" in the API documentation.
- Introduced new tests to validate the rendering of nullable types, including scalar and complex types.
- Updated the logic in the PropertyDocumentMixin to correctly identify and handle nullable unions.
- Enhanced the UI to ensure that nullable types do not display union selectors, improving clarity for users.
@alexpmule alexpmule self-assigned this Jan 13, 2026
@alexpmule alexpmule changed the title feat: implement nullable type handling in API documentation @W-11650729 implement nullable type handling in API documentation Jan 13, 2026
@alexpmule alexpmule merged commit b68cdcb into main Jan 13, 2026
4 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.

3 participants