mirror of
https://github.com/open-webui/mcpo
synced 2025-06-26 18:26:58 +00:00
Merge 105063963d
into 4758d30f6c
This commit is contained in:
commit
3eddb1558c
0
src/mcpo/tests/__init__.py
Normal file
0
src/mcpo/tests/__init__.py
Normal file
@ -310,3 +310,18 @@ def test_multi_type_property_with_any_of():
|
||||
|
||||
# assert result_field parameter config
|
||||
assert result_field.description == "A property with multiple types"
|
||||
|
||||
|
||||
def test_ref_to_parent_node():
|
||||
schema = {'$ref': '#/properties/data/properties/children/items'}
|
||||
result_type, result_field = _process_schema_property(
|
||||
_model_cache,
|
||||
schema,
|
||||
"generate_fishbone_diagram_form_model_data_model_children_item_model_children",
|
||||
"item",
|
||||
False,
|
||||
{}
|
||||
)
|
||||
|
||||
assert result_type == Any
|
||||
assert result_field.description == ""
|
@ -93,6 +93,19 @@ def _process_schema_property(
|
||||
"""
|
||||
if "$ref" in prop_schema:
|
||||
ref = prop_schema["$ref"]
|
||||
if ref.startswith("#/properties/"):
|
||||
# Remove common prefix in pathes.
|
||||
prefix_path = model_name_prefix.split("_form_model_")[-1]
|
||||
ref_path = ref.split("#/properties/")[-1]
|
||||
# Translate $ref path to model_name_prefix style.
|
||||
ref_path = ref_path.replace("/properties/", "_model_")
|
||||
ref_path = ref_path.replace("/items", "_item")
|
||||
# If $ref path is a prefix substring of model_name_prefix path,
|
||||
# there exists a circular reference.
|
||||
# The loop should be broke with a return to avoid exception.
|
||||
if prefix_path.startswith(ref_path):
|
||||
# TODO: Find the exact type hint for the $ref.
|
||||
return Any, Field(default=None, description="")
|
||||
ref = ref.split("/")[-1]
|
||||
assert ref in schema_defs, "Custom field not found"
|
||||
prop_schema = schema_defs[ref]
|
||||
|
Loading…
Reference in New Issue
Block a user