forked from Botts-Innovative-Research/OSHConnect-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_utils.py
More file actions
39 lines (31 loc) · 1.01 KB
/
api_utils.py
File metadata and controls
39 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations
from pydantic import BaseModel, Field, HttpUrl, field_validator
class Link(BaseModel):
href: HttpUrl = Field(...)
rel: str = Field(None)
type: str = Field(None)
hreflang: str = Field(None)
title: str = Field(None)
uid: URI = Field(None)
rt: URI = Field(None)
interface: URI = Field(None, serialization_alias='if')
class UCUMCode(BaseModel):
code: str = Field(...)
label: str = Field(None)
@field_validator('code', 'label')
@classmethod
def validate_string_fields(cls, v):
if isinstance(v, str) and len(v) > 0:
return v
else:
raise ValueError('code and label must be strings of length > 0')
class URI(BaseModel):
href: HttpUrl = Field(...)
label: str = Field(None)
@field_validator('label')
@classmethod
def validate_label(cls, v):
if isinstance(v, str) and len(v) > 0:
return v
else:
raise ValueError('label must be strings of length > 0')