Kriskras99 opened a new issue, #400:
URL: https://github.com/apache/avro-rs/issues/400
`AvroSchemaComponent` looks like this:
```rust
pub trait AvroSchemaComponent {
fn get_schema_in_ctxt(named_schemas: &mut Names, enclosing_namespace:
&Namespace) -> Schema;
}
```
but looking at the code generated by `#[derive(AvroSchema)]` we only insert
`Schema::Ref`s into that map:
```rust
impl #impl_generics apache_avro::AvroSchemaComponent for #ident #ty_generics
#where_clause {
fn get_schema_in_ctxt(named_schemas: &mut
std::collections::HashMap<apache_avro::schema::Name,
apache_avro::schema::Schema>, enclosing_namespace: &Option<String>) ->
apache_avro::schema::Schema {
let name =
apache_avro::schema::Name::new(#full_schema_name).expect(&format!("Unable to
parse schema name {}",
#full_schema_name)[..]).fully_qualified_name(enclosing_namespace);
let enclosing_namespace = &name.namespace;
if named_schemas.contains_key(&name) {
apache_avro::schema::Schema::Ref{name: name.clone()}
} else {
named_schemas.insert(name.clone(),
apache_avro::schema::Schema::Ref{name: name.clone()});
#schema_def
}
}
}
```
As the key is the name, we could also just use a `HashSet` instead:
```rust
impl #impl_generics apache_avro::AvroSchemaComponent for #ident #ty_generics
#where_clause {
fn get_schema_in_ctxt(named_schemas: &mut
std::collections::HashSet<apache_avro::schema::Name, enclosing_namespace:
&Option<String>) -> apache_avro::schema::Schema {
let name =
apache_avro::schema::Name::new(#full_schema_name).expect(&format!("Unable to
parse schema name {}",
#full_schema_name)[..]).fully_qualified_name(enclosing_namespace);
let enclosing_namespace = &name.namespace;
if named_schemas.get(&name).is_some() {
apache_avro::schema::Schema::Ref{name}
} else {
named_schemas.insert(name.clone());
#schema_def
}
}
}
```
If we are supposed to put actual schemas in there, then we are generating
the wrong code and should be generating something like this instead:
```rust
impl #impl_generics apache_avro::AvroSchemaComponent for #ident #ty_generics
#where_clause {
fn get_schema_in_ctxt(named_schemas: &mut
std::collections::HashMap<apache_avro::schema::Name,
apache_avro::schema::Schema>, enclosing_namespace: &Option<String>) ->
apache_avro::schema::Schema {
let name =
apache_avro::schema::Name::new(#full_schema_name).expect(&format!("Unable to
parse schema name {}",
#full_schema_name)[..]).fully_qualified_name(enclosing_namespace);
let enclosing_namespace = &name.namespace;
if named_schemas.contains_key(&name) {
apache_avro::schema::Schema::Ref{name: name.clone()}
} else {
let schema = #schema_def
named_schemas.insert(name, schema.clone())
schema
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]