Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion polyapi/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ def clean_title(title: str) -> str:

def map_primitive_types(type_: str) -> str:
# Define your mapping logic here
return JSONSCHEMA_TO_PYTHON_TYPE_MAP.get(type_, "Any")
return JSONSCHEMA_TO_PYTHON_TYPE_MAP.get(type_, "Any")


def is_primitive(type_: str) -> bool:
return type_ in JSONSCHEMA_TO_PYTHON_TYPE_MAP
9 changes: 8 additions & 1 deletion polyapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
wrapped_generate_schema_types,
clean_title,
map_primitive_types,
is_primitive
)


Expand Down Expand Up @@ -140,11 +141,17 @@ def get_type_and_def(
# TODO fix me
# we don't use ReturnType as name for the list type here, we use _ReturnTypeItem
return "List", ""
elif title and title == "ReturnType" and schema.get("type"):
assert isinstance(title, str)
schema_type = schema.get("type", "Any")
root_type, generated_code = wrapped_generate_schema_types(schema, schema_type, "Dict") # type: ignore
return (map_primitive_types(root_type), "") if is_primitive(root_type) else (root_type, generated_code) # type: ignore
elif title:
assert isinstance(title, str)
# For no-types mode, avoid complex schema generation
try:
return wrapped_generate_schema_types(schema, title, "Dict") # type: ignore
root_type, generated_code = wrapped_generate_schema_types(schema, title, "Dict") # type: ignore
return ("Any", "") if root_type == "ReturnType" else wrapped_generate_schema_types(schema, title, "Dict") # type: ignore
except:
return "Dict", ""
elif schema.get("allOf") and len(schema["allOf"]):
Expand Down