2525
2626def generate_schemas (specs : List [SchemaSpecDto ], limit_ids : List [str ] = None ):
2727 failed_schemas = []
28+ successful_schemas = []
2829 if limit_ids :
2930 for spec in specs :
3031 if spec ["id" ] in limit_ids :
3132 try :
3233 create_schema (spec )
34+ successful_schemas .append (f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} " )
3335 except Exception as e :
3436 schema_path = f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} "
3537 schema_id = spec .get ('id' , 'unknown' )
@@ -40,6 +42,7 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
4042 for spec in specs :
4143 try :
4244 create_schema (spec )
45+ successful_schemas .append (f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} " )
4346 except Exception as e :
4447 schema_path = f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} "
4548 schema_id = spec .get ('id' , 'unknown' )
@@ -51,6 +54,37 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
5154 logging .warning (f"WARNING: { len (failed_schemas )} schema(s) failed to generate:" )
5255 for failed_schema in failed_schemas :
5356 logging .warning (f" - { failed_schema } " )
57+ logging .warning (f"Successfully generated { len (successful_schemas )} schema(s)" )
58+
59+
60+ def validate_schema_content (schema_content : str , schema_name : str ) -> bool :
61+ """
62+ Validate that the schema content is meaningful and not just imports.
63+ Returns True if the schema is valid, False otherwise.
64+ """
65+ if not schema_content or not schema_content .strip ():
66+ logging .debug (f"Schema { schema_name } failed validation: Empty content" )
67+ return False
68+
69+ lines = schema_content .strip ().split ('\n ' )
70+
71+ # Check if the content has any actual class definitions or type aliases
72+ has_class_definition = any (line .strip ().startswith ('class ' ) for line in lines )
73+ has_type_alias = any (schema_name in line and '=' in line and not line .strip ().startswith ('#' ) for line in lines )
74+
75+ # Check if it's essentially just imports (less than 5 lines and no meaningful definitions)
76+ meaningful_lines = [line for line in lines if line .strip () and not line .strip ().startswith ('from ' ) and not line .strip ().startswith ('import ' ) and not line .strip ().startswith ('#' )]
77+
78+ # Enhanced logging for debugging
79+ if not (has_class_definition or has_type_alias ) or len (meaningful_lines ) < 1 :
80+ # Determine the specific reason for failure
81+ if len (meaningful_lines ) == 0 :
82+ logging .debug (f"Schema { schema_name } failed validation: No meaningful content (only imports) - likely empty object or unresolved reference" )
83+ elif not has_class_definition and not has_type_alias :
84+ logging .debug (f"Schema { schema_name } failed validation: No class definition or type alias found" )
85+ return False
86+
87+ return True
5488
5589
5690def add_schema_file (
@@ -75,9 +109,9 @@ def add_schema_file(
75109
76110 schema_defs = render_poly_schema (spec )
77111
78- if not schema_defs :
79- # If render_poly_schema failed and returned empty string, don't create any files
80- raise Exception ("Schema rendering failed - empty schema content returned " )
112+ # Validate schema content before proceeding
113+ if not validate_schema_content ( schema_defs , schema_name ):
114+ raise Exception (f "Schema rendering failed or produced invalid content for { schema_name } " )
81115
82116 # Prepare all content first before writing any files
83117 schema_namespace = to_func_namespace (schema_name )
0 commit comments