Skip to content

Slack Thread #1

@manulera

Description

@manulera

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions