-
Notifications
You must be signed in to change notification settings - Fork 0
470: feat: Make Schema::denormalize public
#50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,11 +398,13 @@ impl Schema { | |
| /// Returns the [Parsing Canonical Form] of `self` that is self contained (not dependent on | ||
| /// any definitions in `schemata`) | ||
| /// | ||
| /// If your require a self contained schema including `default` and `doc` attributes, see [`denormalize`][Schema::denormalize]. | ||
| /// | ||
| /// [Parsing Canonical Form]: | ||
| /// https://avro.apache.org/docs/++version++/specification/#parsing-canonical-form-for-schemas | ||
| pub fn independent_canonical_form(&self, schemata: &[Schema]) -> Result<String, Error> { | ||
| let mut this = self.clone(); | ||
| this.denormalize(schemata, &mut HashSet::with_capacity(schemata.len()))?; | ||
| this.denormalize(schemata)?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call to
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-but-wont-fix; category:bug; feedback: The Gemini AI reviewer is correct! But since this is a manually created Schema instance (in contrast to a parsed one) this is responsibility of the application developer to create a valid and usable Schema. |
||
| Ok(this.canonical_form()) | ||
| } | ||
|
|
||
|
|
@@ -688,7 +690,18 @@ impl Schema { | |
| UnionSchema::new(schemas).map(Schema::Union) | ||
| } | ||
|
|
||
| fn denormalize( | ||
| /// Remove all external references from the schema. | ||
| /// | ||
| /// `schemata` must contain all externally referenced schemas. | ||
| /// | ||
| /// # Errors | ||
| /// Will return a [`Details::SchemaResolutionError`] if it fails to find | ||
| /// a referenced schema. This will put the schema in a partly denormalized state. | ||
| pub fn denormalize(&mut self, schemata: &[Schema]) -> AvroResult<()> { | ||
| self.denormalize_inner(schemata, &mut HashSet::new()) | ||
| } | ||
|
Comment on lines
+693
to
+702
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New public API leaves The doc comment mentions this, but exposing it publicly makes it a real footgun: a caller who handles the 🛡️ Proposed atomic implementation pub fn denormalize(&mut self, schemata: &[Schema]) -> AvroResult<()> {
- self.denormalize_inner(schemata, &mut HashSet::new())
+ let mut candidate = self.clone();
+ candidate.denormalize_inner(schemata, &mut HashSet::with_capacity(schemata.len()))?;
+ *self = candidate;
+ Ok(())
}This also restores the 🤖 Prompt for AI Agents
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:valid-but-wont-fix; category:bug; feedback: The CodeRabbit AI reviewer is correct that this will solve the issue with the partially denormalized schema. But a partially denormalised schema is still a valid schema. If the user does not want a partially denormalized schema then they can clone it before attempting to denormalize. |
||
|
|
||
| fn denormalize_inner( | ||
| &mut self, | ||
| schemata: &[Schema], | ||
| defined_names: &mut HashSet<Name>, | ||
|
|
@@ -708,7 +721,7 @@ impl Schema { | |
| .find(|s| s.name().map(|n| *n == *name).unwrap_or(false)); | ||
| if let Some(schema) = replacement_schema { | ||
| let mut denorm = schema.clone(); | ||
| denorm.denormalize(schemata, defined_names)?; | ||
| denorm.denormalize_inner(schemata, defined_names)?; | ||
| *self = denorm; | ||
| } else { | ||
| return Err(Details::SchemaResolutionError(name.clone()).into()); | ||
|
|
@@ -717,18 +730,22 @@ impl Schema { | |
| Schema::Record(record_schema) => { | ||
| defined_names.insert(record_schema.name.clone()); | ||
| for field in &mut record_schema.fields { | ||
| field.schema.denormalize(schemata, defined_names)?; | ||
| field.schema.denormalize_inner(schemata, defined_names)?; | ||
| } | ||
| } | ||
| Schema::Array(array_schema) => { | ||
| array_schema.items.denormalize(schemata, defined_names)?; | ||
| array_schema | ||
| .items | ||
| .denormalize_inner(schemata, defined_names)?; | ||
| } | ||
| Schema::Map(map_schema) => { | ||
| map_schema.types.denormalize(schemata, defined_names)?; | ||
| map_schema | ||
| .types | ||
| .denormalize_inner(schemata, defined_names)?; | ||
| } | ||
| Schema::Union(union_schema) => { | ||
| for schema in &mut union_schema.schemas { | ||
| schema.denormalize(schemata, defined_names)?; | ||
| schema.denormalize_inner(schemata, defined_names)?; | ||
| } | ||
| } | ||
| schema if schema.is_named() => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in doc comment: "your require" → "you require"
📝 Fix
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:good-to-have; category:typo; feedback: The CodeRabbit AI reviewer is correct! There is a minor typo in the documentation that should be fixed before merging the pull request.