fix(interpreter): apply nullable schema property to model isNullable#2527
Open
armorbreak001 wants to merge 2 commits into
Open
fix(interpreter): apply nullable schema property to model isNullable#2527armorbreak001 wants to merge 2 commits into
armorbreak001 wants to merge 2 commits into
Conversation
✅ Deploy Preview for modelina canceled.
|
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
Fixes #2488
When a JSON Schema object has
nullable: true, the interpreter silently ignored it —isNullablewas alwaysfalsefor these properties.Root Cause
interpretSchemaObject()handlestype,format,required, pattern properties, items, properties, allOf/oneOf/anyOf, const, enum, and more — but never checked forschema.nullable.Fix
Add
model.addTypes(null)whenschema.nullableis truthy. This aligns with howCommonModelToMetaModeldeterminesisNullable(it checks ifnullis in the model type array).Impact
nullable: truecorrectly generate| nulltypes@Nullable/ Optional handlingOptional[]in Pydantic modelsisNullableExample
Input schema:
{ "type": "string", "nullable": true }Before:
{ type: "string", isNullable: false }After:
{ type: ["string", "null"], isNullable: true }