Repository navigation
feat(asyncapi): support nullable type arrays (#344) - #345
Open
hafkensite wants to merge 1 commit into
Open
hafkensite wants to merge 1 commit into
hafkensite wants to merge 1 commit into
Conversation
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>
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.
Closes #344.
JSON Schema allows
typeto 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.UnmarshalJSONdecodestypeas raw JSON, the same way it already handlesadditionalProperties. A newasyncapi.UnmarshalTypereturns the type and anIsNullableflag. Other type unions return an explicit error.validate:"required", sonullround-trips.Tests:
UnmarshalTypeunit test, andtest/v3/issues/344(generation, JSON round-trip, validation). Regenerating all other test/example code gives no diffs, excepttest/v3/issues/140and333, which also differ when regenerated onmain.make lint(golangci-lint v1.62.0) fails to type-check the repo with Go 1.27 locally, onmaintoo, so I rango vetandgofmtinstead.🤖 Generated with Claude Code