@@ -47,6 +47,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
4747 validationOptions := config .NewValidationOptions (input .Options ... )
4848 var validationErrors []* errors.ValidationError
4949 var renderedSchema , jsonSchema []byte
50+ var referenceSchema string
5051 var compiledSchema * jsonschema.Schema
5152
5253 if input .Schema == nil {
@@ -69,13 +70,16 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
6970 hash := input .Schema .GoLow ().Hash ()
7071 if cached , ok := validationOptions .SchemaCache .Load (hash ); ok && cached != nil && cached .CompiledSchema != nil {
7172 renderedSchema = cached .RenderedInline
73+ referenceSchema = cached .ReferenceSchema
74+ jsonSchema = cached .RenderedJSON
7275 compiledSchema = cached .CompiledSchema
7376 }
7477 }
7578
7679 // Cache miss or no cache - render and compile
7780 if compiledSchema == nil {
7881 renderedSchema , _ = input .Schema .RenderInline ()
82+ referenceSchema = string (renderedSchema )
7983 jsonSchema , _ = utils .ConvertYAMLtoJSON (renderedSchema )
8084
8185 var err error
@@ -90,7 +94,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
9094 violation := & errors.SchemaValidationFailure {
9195 Reason : fmt .Sprintf ("failed to compile JSON schema: %s" , err .Error ()),
9296 Location : "schema compilation" ,
93- ReferenceSchema : string ( renderedSchema ) ,
97+ ReferenceSchema : referenceSchema ,
9498 }
9599 validationErrors = append (validationErrors , & errors.ValidationError {
96100 ValidationType : helpers .ResponseBodyValidation ,
@@ -103,18 +107,19 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
103107 SpecCol : 0 ,
104108 SchemaValidationErrors : []* errors.SchemaValidationFailure {violation },
105109 HowToFix : "check the response schema for invalid JSON Schema syntax, complex regex patterns, or unsupported schema constructs" ,
106- Context : string ( renderedSchema ) ,
110+ Context : referenceSchema ,
107111 })
108112 return false , validationErrors
109113 }
110114
111115 if validationOptions .SchemaCache != nil {
112116 hash := input .Schema .GoLow ().Hash ()
113117 validationOptions .SchemaCache .Store (hash , & cache.SchemaCacheEntry {
114- Schema : input .Schema ,
115- RenderedInline : renderedSchema ,
116- RenderedJSON : jsonSchema ,
117- CompiledSchema : compiledSchema ,
118+ Schema : input .Schema ,
119+ RenderedInline : renderedSchema ,
120+ ReferenceSchema : referenceSchema ,
121+ RenderedJSON : jsonSchema ,
122+ CompiledSchema : compiledSchema ,
118123 })
119124 }
120125 }
@@ -128,7 +133,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
128133 violation := & errors.SchemaValidationFailure {
129134 Reason : "response is empty" ,
130135 Location : "unavailable" ,
131- ReferenceSchema : string ( renderedSchema ) ,
136+ ReferenceSchema : referenceSchema ,
132137 }
133138 validationErrors = append (validationErrors , & errors.ValidationError {
134139 ValidationType : "response" ,
@@ -140,7 +145,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
140145 SpecCol : 0 ,
141146 SchemaValidationErrors : []* errors.SchemaValidationFailure {violation },
142147 HowToFix : "ensure response object has been set" ,
143- Context : string ( renderedSchema ) , // attach the rendered schema to the error
148+ Context : referenceSchema , // attach the rendered schema to the error
144149 })
145150 return false , validationErrors
146151 }
@@ -151,7 +156,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
151156 violation := & errors.SchemaValidationFailure {
152157 Reason : ioErr .Error (),
153158 Location : "unavailable" ,
154- ReferenceSchema : string ( renderedSchema ) ,
159+ ReferenceSchema : referenceSchema ,
155160 ReferenceObject : string (responseBody ),
156161 }
157162 validationErrors = append (validationErrors , & errors.ValidationError {
@@ -164,7 +169,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
164169 SpecCol : 0 ,
165170 SchemaValidationErrors : []* errors.SchemaValidationFailure {violation },
166171 HowToFix : "ensure body is not empty" ,
167- Context : string ( renderedSchema ) , // attach the rendered schema to the error
172+ Context : referenceSchema , // attach the rendered schema to the error
168173 })
169174 return false , validationErrors
170175 }
@@ -182,7 +187,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
182187 violation := & errors.SchemaValidationFailure {
183188 Reason : err .Error (),
184189 Location : "unavailable" ,
185- ReferenceSchema : string ( renderedSchema ) ,
190+ ReferenceSchema : referenceSchema ,
186191 ReferenceObject : string (responseBody ),
187192 }
188193 validationErrors = append (validationErrors , & errors.ValidationError {
@@ -195,7 +200,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
195200 SpecCol : 0 ,
196201 SchemaValidationErrors : []* errors.SchemaValidationFailure {violation },
197202 HowToFix : errors .HowToFixInvalidSchema ,
198- Context : string ( renderedSchema ) , // attach the rendered schema to the error
203+ Context : referenceSchema , // attach the rendered schema to the error
199204 })
200205 return false , validationErrors
201206 }
@@ -252,7 +257,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
252257 FieldName : helpers .ExtractFieldNameFromStringLocation (er .InstanceLocation ),
253258 FieldPath : helpers .ExtractJSONPathFromStringLocation (er .InstanceLocation ),
254259 InstancePath : helpers .ConvertStringLocationToPathSegments (er .InstanceLocation ),
255- ReferenceSchema : string ( renderedSchema ) ,
260+ ReferenceSchema : referenceSchema ,
256261 ReferenceObject : referenceObject ,
257262 OriginalError : jk ,
258263 }
@@ -295,7 +300,7 @@ func ValidateResponseSchema(input *ValidateResponseSchemaInput) (bool, []*errors
295300 SpecCol : col ,
296301 SchemaValidationErrors : schemaValidationErrors ,
297302 HowToFix : errors .HowToFixInvalidSchema ,
298- Context : string ( renderedSchema ) , // attach the rendered schema to the error
303+ Context : referenceSchema , // attach the rendered schema to the error
299304 })
300305 }
301306 if len (validationErrors ) > 0 {
0 commit comments