Skip to content

Commit

Permalink
Refactor tag on type usage instead of type definition (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <[email protected]>
  • Loading branch information
patrickpa authored Jun 12, 2024
1 parent 2ffbfd5 commit ade40c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion qc_baselib/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IssueSeverity(enum.IntEnum):


# Common types for both schemas
class ParamType(BaseXmlModel, tag="Param"):
class ParamType(BaseXmlModel):
name: Annotated[str, Field(min_length=1)] | None = attr(name="name")
value: Annotated[Union[str, int, float], Field()] | None = attr(
name="value", default_factory=str
Expand Down
22 changes: 11 additions & 11 deletions qc_baselib/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import List, Any
from pydantic import model_validator
from pydantic_xml import BaseXmlModel, attr
from pydantic_xml import BaseXmlModel, attr, element

from .common import ParamType, IssueSeverity

Expand All @@ -14,21 +14,21 @@
# > https://github.com/asam-ev/qc-framework/blob/develop/doc/schema/config_format.xsd


class CheckerType(BaseXmlModel, tag="Checker"):
params: List[ParamType] = []
class CheckerType(BaseXmlModel):
params: List[ParamType] = element(tag="Param", default=[])
checker_id: str = attr(name="checkerId")
max_level: int = attr(name="maxLevel")
min_level: int = attr(name="minLevel")


class ReportModuleType(BaseXmlModel, tag="ReportModule"):
params: List[ParamType] = []
class ReportModuleType(BaseXmlModel):
params: List[ParamType] = element(tag="Param", default=[])
application: str = attr(name="application")


class CheckerBundleType(BaseXmlModel, tag="CheckerBundle"):
params: List[ParamType] = []
checkers: List[CheckerType] = []
class CheckerBundleType(BaseXmlModel):
params: List[ParamType] = element(tag="Param", default=[])
checkers: List[CheckerType] = element(tag="Checker", default=[])
application: str = attr(name="application")

@model_validator(mode="after")
Expand All @@ -41,9 +41,9 @@ def check_at_least_one_element(self) -> Any:


class Config(BaseXmlModel, tag="Config"):
params: List[ParamType] = []
reports: List[ReportModuleType] = []
checker_bundles: List[CheckerBundleType] = []
params: List[ParamType] = element(tag="Param", default=[])
reports: List[ReportModuleType] = element(tag="ReportModule", default=[])
checker_bundles: List[CheckerBundleType] = element(tag="CheckerBundle", default=[])

@model_validator(mode="after")
def check_at_least_one_element(self) -> Any:
Expand Down
39 changes: 20 additions & 19 deletions qc_baselib/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@
# > https://github.com/asam-ev/qc-framework/blob/develop/doc/schema/xqar_report_format.xsd


class XMLLocationType(BaseXmlModel, tag="XMLLocation"):
class XMLLocationType(BaseXmlModel):
xpath: str = attr(name="xpath")


class InertialLocationType(BaseXmlModel, tag="InertialLocation"):
class InertialLocationType(BaseXmlModel):
x: float = attr(name="x")
y: float = attr(name="y")
z: float = attr(name="z")


class FileLocationType(BaseXmlModel, tag="FileLocation"):
class FileLocationType(BaseXmlModel):
column: int = attr(name="column")
row: int = attr(name="row")
file_type: str = attr(name="fileType")


class LocationType(BaseXmlModel, tag="Locations"):
file_location: List[FileLocationType] = []
xml_location: List[XMLLocationType] = []
inertial_location: List[InertialLocationType] = []
class LocationType(BaseXmlModel):
file_location: List[FileLocationType] = element(tag="FileLocation", default=[])
xml_location: List[XMLLocationType] = element(tag="XMLLocation", default=[])
inertial_location: List[InertialLocationType] = element(
tag="InertialLocation", default=[]
)
description: str = attr(name="description")

@model_validator(mode="after")
Expand All @@ -54,7 +56,7 @@ def check_at_least_one_element(self) -> Any:
return self


class RuleType(BaseXmlModel, tag="AddressedRule"):
class RuleType(BaseXmlModel):
"""
Type containing the Rule Schema rules and its required checks
Expand Down Expand Up @@ -161,10 +163,9 @@ class DomainSpecificInfoType(

class IssueType(
BaseXmlModel,
tag="Issue",
arbitrary_types_allowed=True,
):
locations: List[LocationType] = []
locations: List[LocationType] = element(tag="Locations", default=[])
issue_id: int = attr(name="issueId")
description: str = attr(name="description")
level: IssueSeverity = attr(name="level")
Expand All @@ -182,7 +183,7 @@ class IssueType(
)


class MetadataType(BaseXmlModel, tag="Metadata"):
class MetadataType(BaseXmlModel):
key: str = attr(name="key")
value: str = attr(name="value")
description: str = attr(name="description")
Expand All @@ -194,10 +195,10 @@ class StatusType(str, enum.Enum):
SKIPPED = "skipped"


class CheckerType(BaseXmlModel, tag="Checker", validate_assignment=True):
addressed_rule: List[RuleType] = []
issues: List[IssueType] = []
metadata: List[MetadataType] = []
class CheckerType(BaseXmlModel, validate_assignment=True):
addressed_rule: List[RuleType] = element(tag="AddressedRule", default=[])
issues: List[IssueType] = element(tag="Issue", default=[])
metadata: List[MetadataType] = element(tag="Metadata", default=[])
status: StatusType = attr(name="status", default=None)
checker_id: str = attr(name="checkerId")
description: str = attr(name="description")
Expand Down Expand Up @@ -227,9 +228,9 @@ def check_skipped_status_containing_issues(self) -> Any:
return self


class CheckerBundleType(BaseXmlModel, tag="CheckerBundle"):
params: List[ParamType] = []
checkers: List[CheckerType] = []
class CheckerBundleType(BaseXmlModel):
params: List[ParamType] = element(tag="Param", default=[])
checkers: List[CheckerType] = element(tag="Checker", default=[])
build_date: str = attr(name="build_date")
description: str = attr(name="description")
name: str = attr(name="name")
Expand All @@ -238,5 +239,5 @@ class CheckerBundleType(BaseXmlModel, tag="CheckerBundle"):


class CheckerResults(BaseXmlModel, tag="CheckerResults"):
checker_bundles: List[CheckerBundleType] = []
checker_bundles: List[CheckerBundleType] = element(tag="CheckerBundle", default=[])
version: str = attr(name="version")

0 comments on commit ade40c7

Please sign in to comment.