From f4a0457633f6bd4a93109d621f895b9fd5842225 Mon Sep 17 00:00:00 2001 From: Thor Whalen Date: Fri, 22 Mar 2024 15:15:39 +0100 Subject: [PATCH] feat: add default_default and default_annotation control in json_schema_to_signature --- ju/json_schema.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ju/json_schema.py b/ju/json_schema.py index 4e6f65c..7049742 100644 --- a/ju/json_schema.py +++ b/ju/json_schema.py @@ -211,7 +211,11 @@ def function_to_json_schema( def json_schema_to_signature( - json_schema: dict, *, type_mapper: Mapper = DFLT_JSON_PY_TYPE_PAIRS + json_schema: dict, + *, + type_mapper: Mapper = DFLT_JSON_PY_TYPE_PAIRS, + default_default=Parameter.empty, + default_annotation=Parameter.empty, ): """ Transforms a JSON schema to a Python function signature. @@ -238,7 +242,7 @@ def json_schema_to_signature( """ - type_mapper = ensure_callable_mapper(type_mapper) + type_mapper = ensure_callable_mapper(type_mapper, default=default_annotation) properties = json_schema['properties'] def _params(): @@ -252,7 +256,7 @@ def _params(): py_type = Union[tuple(json_types)] else: py_type = Parameter.empty - default = field.get('default', Parameter.empty) + default = field.get('default', default_default) yield Parameter( name=name, annotation=py_type,