retain doc field when parsing schema
MODIFY
fastavro/_schema.pyx
fastavro/_schema.pyx
@@ -92,6 +92,9 @@ cdef _parse_schema(schema, namespace, _write_hint, named_schemas):
}
parsed_schema["type"] = schema_type
+ if "doc" in schema:
+ parsed_schema["doc"] = schema["doc"]
+
# Correctness checks for logical types
logical_type = parsed_schema.get("logicalType")
if logical_type == "decimal":

MODIFY
fastavro/_schema_py.py
fastavro/_schema_py.py
@@ -119,6 +119,9 @@ def _parse_schema(schema, namespace, _write_hint, named_schemas):
}
parsed_schema["type"] = schema_type
+ if "doc" in schema:
+ parsed_schema["doc"] = schema["doc"]
+
# Correctness checks for logical types
logical_type = parsed_schema.get("logicalType")
if logical_type == "decimal":

MODIFY
tests/test_schema.py
tests/test_schema.py
@@ -234,3 +234,19 @@ def test_named_type_cannot_be_redefined():
SchemaParseException, match="redefined named type: ThatName"
):
parse_schema(schema)
+
+
+def test_doc_left_in_parse_schema():
+ schema = {
+ "type": "record",
+ "name": "test_doc_left_in_parse_schema",
+ "doc": "blah",
+ "fields": [
+ {
+ "name": "field1",
+ "type": "string",
+ "default": ""
+ }
+ ]
+ }
+ assert schema == parse_schema(schema, _write_hint=False)

retain doc field when parsing schema (#398)