@@ -79,8 +79,33 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
7979 // Cache miss or no cache - render and compile
8080 if compiledSchema == nil {
8181 renderCtx := base .NewInlineRenderContext ()
82- renderedSchema , _ = input .Schema .RenderInlineWithContext (renderCtx )
82+ var renderErr error
83+ renderedSchema , renderErr = input .Schema .RenderInlineWithContext (renderCtx )
8384 referenceSchema = string (renderedSchema )
85+
86+ // If rendering failed (e.g., circular reference), return the render error
87+ if renderErr != nil {
88+ violation := & errors.SchemaValidationFailure {
89+ Reason : renderErr .Error (),
90+ Location : "schema rendering" ,
91+ ReferenceSchema : referenceSchema ,
92+ }
93+ validationErrors = append (validationErrors , & errors.ValidationError {
94+ ValidationType : helpers .ResponseBodyValidation ,
95+ ValidationSubType : helpers .Schema ,
96+ Message : fmt .Sprintf ("%d response body for '%s' failed schema rendering" ,
97+ input .Response .StatusCode , input .Request .URL .Path ),
98+ Reason : fmt .Sprintf ("The response schema for status code '%d' failed to render: %s" ,
99+ input .Response .StatusCode , renderErr .Error ()),
100+ SpecLine : 1 ,
101+ SpecCol : 0 ,
102+ SchemaValidationErrors : []* errors.SchemaValidationFailure {violation },
103+ HowToFix : "check the response schema for circular references or invalid structures" ,
104+ Context : referenceSchema ,
105+ })
106+ return false , validationErrors
107+ }
108+
84109 jsonSchema , _ = utils .ConvertYAMLtoJSON (renderedSchema )
85110
86111 var err error
0 commit comments