def get_schema_dict(record, state=None): state = state or SchemaGeneratorState() full_name = core.get_full_name(record) if '.' in full_name: namespace, record_name = full_name.rsplit('.', 1) else: namespace = None record_name = record._schema_name if record_name in state.declared_records: return record_name state.declared_records.add(record_name) avro_record = { "type": "record", "name": record._schema_name, } if namespace: avro_record["namespace"] = namespace if record.__doc__ is not None: avro_record["doc"] = record.__doc__ avro_fields = [] for field_name, field_type in record._fields.iteritems(): field_spec = { "name": field_name, "type": field_type.avro_type_schema(state) } if field_type.default is not core.NO_DEFAULT: field_spec["default"] = field_type.avro_default_value() if field_type.description is not None: field_spec["doc"] = field_type.description avro_fields.append(field_spec) avro_record["fields"] = avro_fields return avro_record
def avro_type_name(self): return core.get_full_name(self._schema)