@@ -145,9 +145,6 @@ public JsonNode GetSchema(Reflector reflector, Type type, JsonObject? defines =
145145
146146 schema = schemeConvertor . GetSchema ( ) ;
147147
148- if ( definesNeeded && ! defineContainsType )
149- defines [ typeId ] = schema ;
150-
151148 foreach ( var defType in schemeConvertor . GetDefinedTypes ( ) )
152149 {
153150 var defTypeId = defType . GetSchemaTypeId ( ) ;
@@ -182,6 +179,10 @@ public JsonNode GetSchema(Reflector reflector, Type type, JsonObject? defines =
182179 defines [ defTypeId ] = defSchema ;
183180 }
184181
182+ // Add placeholder to prevent infinite recursion
183+ if ( definesNeeded && ! defineContainsType )
184+ defines [ typeId ] = new JsonObject { [ Type ] = Object } ;
185+
185186 if ( genericArgs . Length >= 2 )
186187 {
187188 // Use the value type's schema for additionalProperties
@@ -192,22 +193,29 @@ public JsonNode GetSchema(Reflector reflector, Type type, JsonObject? defines =
192193 {
193194 schema = new JsonObject { [ Type ] = Object , [ AdditionalProperties ] = true } ;
194195 }
195-
196- if ( definesNeeded && ! defineContainsType )
197- defines [ typeId ] = schema ;
198196 }
199197 else
200198 {
201- schema = GenerateSchemaFromType ( reflector , type , defines ) ;
199+ // Add placeholder to prevent infinite recursion
200+ if ( definesNeeded && ! defineContainsType )
201+ defines [ typeId ] = new JsonObject { [ Type ] = Object } ;
202202
203- if ( definesNeeded && defines . Count > 0 )
204- schema [ Defs ] = defines ;
203+ schema = GenerateSchemaFromType ( reflector , type , defines ) ;
205204 }
206205
207206 // Get description from the type if available
208207 var description = TypeUtils . GetDescription ( type ) ;
209208 if ( ! string . IsNullOrEmpty ( description ) )
210209 schema [ Description ] = JsonValue . Create ( description ) ;
210+
211+ if ( definesNeeded )
212+ {
213+ if ( ! defineContainsType )
214+ defines [ typeId ] = schema . DeepClone ( ) ;
215+
216+ if ( defines . Count > 0 )
217+ schema [ Defs ] = defines ;
218+ }
211219 }
212220 catch ( Exception ex )
213221 {
0 commit comments