mirror of
				https://github.com/open-webui/mcpo
				synced 2025-06-26 18:26:58 +00:00 
			
		
		
		
	Merge pull request #174 from bipedalBit/fix-circular-schema-ref-exception
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Has been cancelled
				
			
		
			
				
	
				Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Has been cancelled
				
			
		
			
				
	
				Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Has been cancelled
				
			Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Has been cancelled
				
			Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
				
			fix: return to break loop of $ref in schema, avoid some case of Custo…
This commit is contained in:
		
						commit
						105063963d
					
				
							
								
								
									
										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