@@ -97,6 +97,28 @@ func buildJsonRender(schema *base.Schema) ([]byte, error) {
9797 return utils .ConvertYAMLtoJSON (renderedSchema )
9898}
9999
100+ // GetRenderedSchema returns a JSON string representation of the schema for error messages.
101+ // It first checks the schema cache for a pre-rendered version, falling back to fresh rendering.
102+ // This avoids expensive re-rendering on each validation when the cache is available.
103+ func GetRenderedSchema (schema * base.Schema , opts * config.ValidationOptions ) string {
104+ if schema == nil {
105+ return ""
106+ }
107+
108+ // Try cache lookup first
109+ if opts != nil && opts .SchemaCache != nil && schema .GoLow () != nil {
110+ hash := schema .GoLow ().Hash ()
111+ if cached , ok := opts .SchemaCache .Load (hash ); ok && cached != nil && len (cached .RenderedJSON ) > 0 {
112+ return string (cached .RenderedJSON )
113+ }
114+ }
115+
116+ // Cache miss - render fresh
117+ rendered , _ := schema .RenderInline ()
118+ schemaBytes , _ := json .Marshal (rendered )
119+ return string (schemaBytes )
120+ }
121+
100122// ValidateParameterSchema will validate a parameter against a raw object, or a blob of json/yaml.
101123// It will return a list of validation errors, if any.
102124//
@@ -128,7 +150,6 @@ func ValidateParameterSchema(
128150 hash := schema .GoLow ().Hash ()
129151 if cached , ok := validationOptions .SchemaCache .Load (hash ); ok && cached != nil && cached .CompiledSchema != nil {
130152 jsch = cached .CompiledSchema
131- jsonSchema = cached .RenderedJSON
132153 }
133154 }
134155
0 commit comments