Skip to content

fix(interpreter): apply nullable schema property to model isNullable#2527

Open
armorbreak001 wants to merge 2 commits into
asyncapi:masterfrom
armorbreak001:fix/nullable-isnullable
Open

fix(interpreter): apply nullable schema property to model isNullable#2527
armorbreak001 wants to merge 2 commits into
asyncapi:masterfrom
armorbreak001:fix/nullable-isnullable

Conversation

@armorbreak001

Copy link
Copy Markdown

Summary

Fixes #2488

When a JSON Schema object has nullable: true, the interpreter silently ignored it — isNullable was always false for these properties.

Root Cause

interpretSchemaObject() handles type, format, required, pattern properties, items, properties, allOf/oneOf/anyOf, const, enum, and more — but never checked for schema.nullable.

Fix

Add model.addTypes(null) when schema.nullable is truthy. This aligns with how CommonModelToMetaModel determines isNullable (it checks if null is in the model type array).

Impact

  • ✅ TypeScript: properties with nullable: true correctly generate | null types
  • ✅ Java: correct @Nullable / Optional handling
  • ✅ Go: correct pointer types
  • ✅ Python: correct Optional[] in Pydantic models
  • ✅ All generators that check isNullable

Example

Input schema:

{ "type": "string", "nullable": true }

Before: { type: "string", isNullable: false }
After: { type: ["string", "null"], isNullable: true }

@netlify

netlify Bot commented Apr 19, 2026

Copy link
Copy Markdown

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 2f3bed1
🔍 Latest deploy log https://app.netlify.com/projects/modelina/deploys/69f26fa4bf697b000848e089

armorbreak001 added 2 commits April 30, 2026 04:52
…ld (asyncapi#2494)

alterschema pulls in @hyperjump/pact@0.2.5 which has a broken
postinstall script (rmSync on non-existent 'dist' dir), causing all
Yarn installs to fail with ENOENT.

Changes:
- Remove alterschema dependency (and its 22 transitive deps)
- Add lightweight migrateSchemaTo202012() utility that covers the
  draft-04/06/07 → 2020-12 conversions needed by JsonBinPackPreset:
  • $schema URI update
  • definitions → $defs + pointer rewrite
  • exclusiveMinimum/Maximum boolean → numeric (draft-04)
  • items tuple → prefixItems (draft-04/06)
  • Recursive sub-schema migration

Tested: all JsonBinPackPreset snapshot tests pass.
When a schema has `nullable: true`, the interpreter now correctly
adds 'null' to the model's types via model.addTypes('null').

This ensures that generated code properly marks the field as nullable
(e.g., `string | null` in TypeScript, `Optional[str]` in Python).

Fixes asyncapi#2488
@sonarqubecloud

Copy link
Copy Markdown

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.

[BUG] nullable types not applied to isNullable

1 participant