Repository navigation
fix: flatten no longer causes duplicate names - #448
Merged
Merged
Conversation
When a type was used both via `flatten` and directly, the schema generated would contain duplicate names (and schemas). This is because `flatten` would use an empty `named_schemas` to get the record schema. If the existing `named_schemas` was used, `flatten` might get a `Schema::Ref` if the type was already used. Or when `flatten` was used first, if the type was used after it would create a `Schema::Ref` to a schema that does not exist. This is solved by adding a new function to the `AvroSchemaComponent` that returns the fields directly. To not break code currently implementing this trait, it has a default implementation that will work around the issues above. This default implementation is also used for fields with the `#[avro(with = ||)]` and `#[avro(with = path)]` attributes, as they don't have a way to provide the field directly. Users of `#[avro(with)]` will need to implement `get_record_fields_in_ctxt` in their module.
Kriskras99
marked this pull request as draft
January 28, 2026 22:03
Contributor
Author
|
@martin-g this still needs some additional tests, but do you agree with the general direction/implementation of this PR? |
…hemaComponent` The implementation for `serde_json::Map<String, T>` has been removed. This is **not** a breaking change, as `serde_json::Map` can only be constructed for `<String, Value>` and `Value` does not implement `AvroSchemaComponent`.
Kriskras99
marked this pull request as ready for review
January 29, 2026 16:01
Kriskras99
force-pushed
the
fix/avro_schema_flatten
branch
from
January 29, 2026 16:02
c440511 to
f68a652
Compare
martin-g
reviewed
Jan 30, 2026
martin-g
reviewed
Jan 30, 2026
added 3 commits
January 30, 2026 10:49
martin-g
reviewed
Jan 30, 2026
martin-g
reviewed
Jan 30, 2026
martin-g
approved these changes
Jan 30, 2026
Closed
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.
When a type was used both via
flattenand directly, the schema generated would contain duplicate names (and schemas). This is becauseflattenwould use an emptynamed_schemasto get the record schema. If the existingnamed_schemaswas used,flattenmight get aSchema::Refif the type was already used. Or whenflattenwas used first, if the type was used after it would create aSchema::Refto a schema that does not exist.This is solved by adding a new function to the
AvroSchemaComponentthat returns the fields directly. To not break code currently implementing this trait, it has a default implementation that will work around the issues above. This default implementation is also used for fields with the#[avro(with = ||)]and#[avro(with = path)]attributes, as they don't have a way to provide the field directly. Users of#[avro(with)]will need to implementget_record_fields_in_ctxtin their module.TODO:
get_record_fields_in_ctxtimplementationtransparentwithfeat/documentationFixes one of the issues raised in #435