Skip to content

feat(asyncapi): support nullable type arrays (#344) - #345

Open
hafkensite wants to merge 1 commit into
lerenn:mainfrom
hafkensite:feat/nullable-type-array
Open

hafkensite wants to merge 1 commit into
lerenn:mainfrom
hafkensite:feat/nullable-type-array

Conversation

@hafkensite

Copy link
Copy Markdown

Closes #344.

JSON Schema allows type to be an array (Draft 07 §6.1.1), and AsyncAPI schemas are a superset of Draft 07 (v3.0.0 Schema Object). This adds support for the nullable form [<type>, "null"] in v2 and v3:

  • Schema.UnmarshalJSON decodes type as raw JSON, the same way it already handles additionalProperties. A new asyncapi.UnmarshalType returns the type and an IsNullable flag. Other type unions return an explicit error.
  • Nullable fields are generated as pointers, even when required, and don't get validate:"required", so null round-trips.

Tests: UnmarshalType unit test, and test/v3/issues/344 (generation, JSON round-trip, validation). Regenerating all other test/example code gives no diffs, except test/v3/issues/140 and 333, which also differ when regenerated on main.

make lint (golangci-lint v1.62.0) fails to type-check the repo with Go 1.27 locally, on main too, so I ran go vet and gofmt instead.

🤖 Generated with Claude Code

JSON Schema allows "type" to be an array. Parse [<type>, "null"] into
the type plus a nullable flag, and generate nullable fields as pointers
without a "required" validation, so null round-trips. Other type unions
return an explicit error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Schema "type" as an array (e.g. [string, "null"]) fails to parse

1 participant