diff --git a/docs/tutorials/customize.md b/docs/tutorials/customize.md index 293c6f2..f7d76f4 100644 --- a/docs/tutorials/customize.md +++ b/docs/tutorials/customize.md @@ -7,7 +7,7 @@ You can customize schema classes on your own code, if you need for some reasons. For example, you can make `Attribute` allow `attribute.json` not to require `description` field as follows: ```python title="custom_attribute.py" -from dataclasses import dataclass +from attrs import define, field from typing import Any from typing_extensions import Self @@ -16,27 +16,16 @@ from t4_devkit.schema import SCHEMAS, SchemaName, SchemaBase from t4_devkit.common.io import load_json -@dataclass +@define @SCHEMAS.register(SchemaName.ATTRIBUTE, force=True) class CustomAttribute(SchemaBase): - """Custom Attribute class ignoring if there is no description field. - Note that `description` field is mandatory by the original definition. + """Custom Attribute class ignoring if there is no `description` field. + Note that `description` field is mandatory in the original `Attribute` class. + + `@SCHEMAS.register(SchemaName.ATTRIBUTE, force=True)` performs that + it forces to update the attribute table in the schema registry. """ - token: str name: str - description: str | None - - @classmehod - def from_json(cls, filepath: str) -> list[Self]: - objs: list[Self] = [] - - record_list: list[dict[str, Any]] = load_json(filepath) - for record in record_list: - token: str = record["token"] - name: str = record["name"] - # Return None if record does not have description field - description: str | None = record.get("description") - objs.append(cls(token=token, name=name, description=description)) - return objs + description: str | None = field(default=None) ```