-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Description
Current spec: https://github.com/doe-iri/iri-facility-api-docs/blob/main/specification/conceptual-model.md#633-resource
Base Named Resource: https://github.com/doe-iri/iri-facility-api-python/blob/main/app/routers/status/models.py#L18-L22
Issues in the current base:
- name and description are optional in spec (not in code)
- self_uri defined in subclasses. Better to define in the main class.
- (Optional, but really beneficial field) include descriptions
Resource model: https://github.com/doe-iri/iri-facility-api-python/blob/main/app/routers/status/models.py#L60-L86
Issues in the resource model:
- capability_ids is internal (not defined in spec and is mandatory)
- current_status is required in spec. optional in code
- Missing located_at_uri and member_of_uri (even those are optional, prefer to have it defined inside the model)
Proposed changes:
from typing import List, Optional
from pydantic import BaseModel, Field, HttpUrl
from .. import iri_router
class NamedObject(BaseModel):
id: str = Field(..., description="Unique identifier for the object (UUID or URN).")
# subclasses must implement this function below
def _self_path(self) -> str:
raise NotImplementedError
@computed_field(description="The canonical URL of this object")
@property
def self_uri(self) -> str:
return f"{config.API_URL_ROOT}{config.API_PREFIX}{config.API_URL}{self._self_path()}"
name: Optional[str] = Field(None, description="The long name of the object.")
description: Optional[str] = Field(None, description="Human-readable description of the object.")
last_modified: iri_router.StrictDateTime = Field(..., description="ISO 8601 timestamp when this object was last modified.")
class Resource(NamedObject):
capability_ids: list[str] | None = Field(default=None, exclude=True) # Keep it optional, not mandatory
resource_type: ResourceType = Field(..., description="The type of Resource.")
group: Optional[str] = Field(None, description="Member resource group.")
current_status: StatusType = Field(..., description="Current operational status of the Resource.")
capability_uris: List[HttpUrl] = Field(default_factory=list, description="URIs of capabilities this Resource provides.")
located_at_uri: Optional[HttpUrl] = Field(None, description="URI of Site containing this Resource.")
member_of_uri: Optional[HttpUrl] = Field(None, description="URI of Facility managing this Resource.")
def _self_path(self) -> str:
return f"/status/resources/{self.id}"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels