@@ -7,7 +7,7 @@ You can customize schema classes on your own code, if you need for some reasons.
77For example, you can make ` Attribute ` allow ` attribute.json ` not to require ` description ` field as follows:
88
99``` python title="custom_attribute.py"
10- from dataclasses import dataclass
10+ from attrs import define, field
1111from typing import Any
1212
1313from typing_extensions import Self
@@ -16,27 +16,16 @@ from t4_devkit.schema import SCHEMAS, SchemaName, SchemaBase
1616from t4_devkit.common.io import load_json
1717
1818
19- @dataclass
19+ @define
2020@SCHEMAS.register (SchemaName.ATTRIBUTE , force = True )
2121class CustomAttribute (SchemaBase ):
22- """ Custom Attribute class ignoring if there is no description field.
23- Note that `description` field is mandatory by the original definition.
22+ """ Custom Attribute class ignoring if there is no `description` field.
23+ Note that `description` field is mandatory in the original `Attribute` class.
24+
25+ `@SCHEMAS.register(SchemaName.ATTRIBUTE, force=True)` performs that
26+ it forces to update the attribute table in the schema registry.
2427 """
2528
26- token: str
2729 name: str
28- description: str | None
29-
30- @classmehod
31- def from_json (cls , filepath : str ) -> list[Self]:
32- objs: list[Self] = []
33-
34- record_list: list[dict[str , Any]] = load_json(filepath)
35- for record in record_list:
36- token: str = record[" token" ]
37- name: str = record[" name" ]
38- # Return None if record does not have description field
39- description: str | None = record.get(" description" )
40- objs.append(cls (token = token, name = name, description = description))
41- return objs
30+ description: str | None = field(default = None )
4231```
0 commit comments