Skip to content

Commit

Permalink
Merge pull request #55 from phenobarbital/new-version
Browse files Browse the repository at this point in the history
fix when exports json schema
  • Loading branch information
phenobarbital authored Nov 1, 2022
2 parents 7e2a388 + 751d323 commit f3f0a3f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions datamodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def schema(cls, as_dict: bool = False) -> Any:
}
elif isinstance(_type, ModelMeta):
t = 'object'
enum_type = None
ref = f"/schemas/{_type.__name__}"
sch = _type.schema(as_dict = True)
defs[name] = sch
Expand Down
6 changes: 6 additions & 0 deletions datamodel/parsers/json.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
JSON Encoder, Decoder.
"""
import uuid
from asyncpg.pgproto import pgproto
from dataclasses import _MISSING_TYPE, MISSING
from typing import Any, Union
from decimal import Decimal
Expand All @@ -26,6 +28,10 @@ cdef class JSONContent:
return float(obj)
elif hasattr(obj, "isoformat"):
return obj.isoformat()
elif isinstance(obj, pgproto.UUID):
return str(obj)
elif isinstance(obj, uuid.UUID):
return obj
elif hasattr(obj, "hex"):
return obj.hex
elif hasattr(obj, 'lower'): # asyncPg Range:
Expand Down
2 changes: 1 addition & 1 deletion datamodel/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = 'python-datamodel'
__description__ = ('simple library based on python +3.8 to use Dataclass-syntax'
'for interacting with Data')
__version__ = '0.1.3'
__version__ = '0.1.5'
__author__ = 'Jesus Lara'
__author_email__ = '[email protected]'
__license__ = 'BSD'
2 changes: 1 addition & 1 deletion examples/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class User(BaseModel):
"""Basic User Model for authentication."""

user_id: int = Column(required=False, primary_key=True, repr=False)
first_name: str = Column(required=True, max=254, label="First Name")
first_name: str = Column(required=True, max=254, label="First Name", pattern="^\w*$")
last_name: str = Column(required=True, max=254, label="Last Name")
email: str = Column(required=False, max=254, label="User's Email")
password: str = Column(required=False, max=16, secret=True, widget='/properties/password')
Expand Down

0 comments on commit f3f0a3f

Please sign in to comment.