25
25
26
26
def generate_schemas (specs : List [SchemaSpecDto ], limit_ids : List [str ] = None ):
27
27
failed_schemas = []
28
+ successful_schemas = []
28
29
if limit_ids :
29
30
for spec in specs :
30
31
if spec ["id" ] in limit_ids :
31
32
try :
32
33
create_schema (spec )
34
+ successful_schemas .append (f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} " )
33
35
except Exception as e :
34
36
schema_path = f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} "
35
37
schema_id = spec .get ('id' , 'unknown' )
@@ -40,6 +42,7 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
40
42
for spec in specs :
41
43
try :
42
44
create_schema (spec )
45
+ successful_schemas .append (f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} " )
43
46
except Exception as e :
44
47
schema_path = f"{ spec .get ('context' , 'unknown' )} .{ spec .get ('name' , 'unknown' )} "
45
48
schema_id = spec .get ('id' , 'unknown' )
@@ -51,6 +54,37 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
51
54
logging .warning (f"WARNING: { len (failed_schemas )} schema(s) failed to generate:" )
52
55
for failed_schema in failed_schemas :
53
56
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
54
88
55
89
56
90
def add_schema_file (
@@ -75,9 +109,9 @@ def add_schema_file(
75
109
76
110
schema_defs = render_poly_schema (spec )
77
111
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 } " )
81
115
82
116
# Prepare all content first before writing any files
83
117
schema_namespace = to_func_namespace (schema_name )
0 commit comments