Skip to content

Commit 6a2916a

Browse files
committed
fix converting default functions into string version during json-schema conversion
1 parent 10570b6 commit 6a2916a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

datamodel/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,11 @@ def schema(cls, as_dict=False):
536536
fields[name]["attrs"]["visible"] = False
537537

538538
if field.default:
539-
fields[name]['default'] = field.default
539+
d = field.default
540+
if is_callable(d):
541+
fields[name]['default'] = f"fn:{d!r}"
542+
else:
543+
fields[name]['default'] = f"{d!s}"
540544

541545
if secret is not None:
542546
fields[name]['secret'] = secret

datamodel/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__title__ = 'python-datamodel'
55
__description__ = ('simple library based on python +3.8 to use Dataclass-syntax'
66
'for interacting with Data')
7-
__version__ = '0.6.25'
7+
__version__ = '0.6.26'
88
__author__ = 'Jesus Lara'
99
__author_email__ = '[email protected]'
1010
__license__ = 'BSD'

examples/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class User(BaseModel):
2727
"""
2828
User Basic Structure
2929
"""
30-
id: uuid.UUID = Column(primary_key=True, required=True, default=auto_now_add(), db_default='uuid_generate_v4()')
30+
id: uuid.UUID = Column(primary_key=True, required=True, default=auto_now_add, db_default='uuid_generate_v4()')
3131
firstname: str
3232
lastname: str
3333
bignumber: np.int64

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def readme():
117117
"Programming Language :: Python :: 3.9",
118118
"Programming Language :: Python :: 3.10",
119119
"Programming Language :: Python :: 3.11",
120+
"Programming Language :: Python :: 3.12",
120121
"Framework :: AsyncIO",
121122
"License :: OSI Approved :: BSD License",
122123
"Operating System :: OS Independent",
@@ -157,7 +158,7 @@ def readme():
157158
test_suite='tests',
158159
ext_modules=cythonize(extensions),
159160
project_urls={ # Optional
160-
"Source": "https://github.com/phenobarbital/datamodels",
161+
"Source": "https://github.com/phenobarbital/datamodel",
161162
"Funding": "https://paypal.me/phenobarbital",
162163
"Say Thanks!": "https://saythanks.io/to/phenobarbital",
163164
},

0 commit comments

Comments
 (0)