You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2024/03/19 13:29:27 UTC

(avro) branch avro-3962-docs-for-fields created (now 74d185770)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a change to branch avro-3962-docs-for-fields
in repository https://gitbox.apache.org/repos/asf/avro.git


      at 74d185770 AVRO-3962: [Rust] Add support for field attribute Rustdoc to AvroSchema

This branch includes the following new commits:

     new 74d185770 AVRO-3962: [Rust] Add support for field attribute Rustdoc to AvroSchema

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(avro) 01/01: AVRO-3962: [Rust] Add support for field attribute Rustdoc to AvroSchema

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch avro-3962-docs-for-fields
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 74d1857705f31966752b4080ae7bb35e4930f489
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Tue Mar 19 15:28:30 2024 +0200

    AVRO-3962: [Rust] Add support for field attribute Rustdoc to AvroSchema
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
 lang/rust/avro_derive/src/lib.rs      |  3 ++-
 lang/rust/avro_derive/tests/derive.rs | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/lang/rust/avro_derive/src/lib.rs b/lang/rust/avro_derive/src/lib.rs
index 419f34cab..8f0138823 100644
--- a/lang/rust/avro_derive/src/lib.rs
+++ b/lang/rust/avro_derive/src/lib.rs
@@ -126,7 +126,8 @@ fn get_data_struct_schema_def(
                 }
                 let field_attrs =
                     FieldOptions::from_attributes(&field.attrs[..]).map_err(darling_to_syn)?;
-                let doc = preserve_optional(field_attrs.doc);
+                let doc =
+                    preserve_optional(field_attrs.doc.or_else(|| extract_outer_doc(&field.attrs)));
                 if let Some(rename) = field_attrs.rename {
                     name = rename
                 }
diff --git a/lang/rust/avro_derive/tests/derive.rs b/lang/rust/avro_derive/tests/derive.rs
index 1fab03203..ec7a96d75 100644
--- a/lang/rust/avro_derive/tests/derive.rs
+++ b/lang/rust/avro_derive/tests/derive.rs
@@ -1571,4 +1571,28 @@ mod test_derive {
             panic!("Unexpected schema type for {derived_schema:?}")
         }
     }
+
+    #[test]
+    fn avro_3962_fields_documentation() {
+        /// Foo docs
+        #[derive(AvroSchema)]
+        #[allow(dead_code)]
+        struct Foo {
+            /// a's Rustdoc
+            a: i32,
+            /// b's Rustdoc
+            #[avro(doc = "attribute doc has priority over Rustdoc")]
+            b: i32,
+        }
+
+        if let Schema::Record(RecordSchema { fields, .. }) = Foo::get_schema() {
+            assert_eq!(fields[0].doc, Some("a's Rustdoc".to_string()));
+            assert_eq!(
+                fields[1].doc,
+                Some("attribute doc has priority over Rustdoc".to_string())
+            );
+        } else {
+            panic!("Unexpected schema type for Foo")
+        }
+    }
 }