Open
Conversation
test Indentation No newlines remove unused import Support namespaces single-key union record types Inline namespace const Support auto union wrapping Update tests for auto-wrapping Wrapping is all-or-nothing avsc treats bytes and fixed the same for ambiguity Add comments, and special case for null
ssonne
commented
Mar 8, 2026
| const output: string[] = []; | ||
| if (isEnumType(schema)) convertEnum(schema, output); | ||
| else if (isRecordType(schema)) convertRecord(schema, output, opts); | ||
| else if (isRecordType(schema)) convertRecord(schema, output, opts, schema.namespace); |
Author
There was a problem hiding this comment.
It might make sense at this point to introduce a "parse context" kind of object to hold output, opts, and namespace instead of passing three variables around everywhere. I didn't do this to keep this PR focused on the new feature.
ssonne
commented
Mar 8, 2026
| export type Schema = RecordType | EnumType; | ||
| export interface ConversionOptions { | ||
| logicalTypes?: { [type: string]: string }; | ||
| wrapUnions?: boolean | "always" | "never" | "auto"; |
Author
There was a problem hiding this comment.
This allows boolean to match the corresponding flag in avsc, so that code that uses both avro-typescript and avsc can use the same definition of the flag. It could also use a tighter definition without the boolean: wrapUnions?: "always" | "never" | "auto"; or even wrapUnions?: "always" | "never" | "avsc-auto"; to make it clear that auto is targeting avsc's behavior.
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.
This is an implementation of the
wrapEnumsoption described in this issue: #43The basic idea is to support generating types compatible with avsc when it requires wrapped enums.
See https://github.com/mtth/avsc/blob/91d653f72906102448a059cb81692177bb678f52/lib/types.js#L3113 for how avsc decides whether a union is ambiguous.