Fixed values in LinkML?
Hello, I have a question regarding fixed values for fields in a class. I am coming at this because I am trying to move from using pydantic models in an API to use LinkML. Let’s imagine I had a class Employee, which has a field employee_type. This field could contain any value from a given enum. Let’s imagine then that we have some subclasses of that Employee that should have constrained values of employee_type.
from pydantic import BaseModel
from enum import Enum
class EmployeeType(str, Enum):
hr = 'hr'
research = 'research'
class Employee(BaseModel):
name: str
employee_type: EmployeeType
class HREmployee(Employee):
employee_type: EmployeeType = EmployeeType.hr
class ResearchEmployee(Employee):
employee_type: EmployeeType = EmployeeType.research
Can you do this in LinkML?
Should I be doing this? In the real use-case, I don’t need this field for python code, but I use an equivalent type field in the javascript frontend to identify the type of object.
Slack Message
Fixed values in LinkML?
Hello, I have a question regarding fixed values for fields in a class. I am coming at this because I am trying to move from using pydantic models in an API to use LinkML. Let’s imagine I had a class
Employee, which has a fieldemployee_type. This field could contain any value from a given enum. Let’s imagine then that we have some subclasses of thatEmployeethat should have constrained values ofemployee_type.Can you do this in LinkML?
Should I be doing this? In the real use-case, I don’t need this field for python code, but I use an equivalent type field in the javascript frontend to identify the type of object.
Slack Message