Skip to content

Commit ab0675e

Browse files
its-hammer-timedaveshanley
authored andcommitted
Fix Cache Warm Bug
1 parent 6a5ab5d commit ab0675e

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

validator.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,17 @@ func warmMediaTypeSchema(mediaType *v3.MediaType, schemaCache cache.SchemaCache,
468468
schema := mediaType.Schema.Schema()
469469
if schema != nil {
470470
renderedInline, _ := schema.RenderInline()
471+
referenceSchema := string(renderedInline)
471472
renderedJSON, _ := utils.ConvertYAMLtoJSON(renderedInline)
472473
if len(renderedInline) > 0 {
473474
compiledSchema, _ := helpers.NewCompiledSchema(fmt.Sprintf("%x", hash), renderedJSON, options)
474475

475476
schemaCache.Store(hash, &cache.SchemaCacheEntry{
476-
Schema: schema,
477-
RenderedInline: renderedInline,
478-
RenderedJSON: renderedJSON,
479-
CompiledSchema: compiledSchema,
477+
Schema: schema,
478+
RenderedInline: renderedInline,
479+
ReferenceSchema: referenceSchema,
480+
RenderedJSON: renderedJSON,
481+
CompiledSchema: compiledSchema,
480482
})
481483
}
482484
}
@@ -513,16 +515,18 @@ func warmParameterSchema(param *v3.Parameter, schemaCache cache.SchemaCache, opt
513515
if schema != nil {
514516
if _, exists := schemaCache.Load(hash); !exists {
515517
renderedInline, _ := schema.RenderInline()
518+
referenceSchema := string(renderedInline)
516519
renderedJSON, _ := utils.ConvertYAMLtoJSON(renderedInline)
517520
if len(renderedInline) > 0 {
518521
compiledSchema, _ := helpers.NewCompiledSchema(fmt.Sprintf("%x", hash), renderedJSON, options)
519522

520523
// Store in cache using the shared SchemaCache type
521524
schemaCache.Store(hash, &cache.SchemaCacheEntry{
522-
Schema: schema,
523-
RenderedInline: renderedInline,
524-
RenderedJSON: renderedJSON,
525-
CompiledSchema: compiledSchema,
525+
Schema: schema,
526+
RenderedInline: renderedInline,
527+
ReferenceSchema: referenceSchema,
528+
RenderedJSON: renderedJSON,
529+
CompiledSchema: compiledSchema,
526530
})
527531
}
528532
}

validator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,8 @@ func TestCacheWarming_PopulatesCache(t *testing.T) {
20132013
validator.options.SchemaCache.Range(func(key [32]byte, value *cache.SchemaCacheEntry) bool {
20142014
count++
20152015
assert.NotNil(t, value.CompiledSchema, "Cache entry should have compiled schema")
2016+
assert.NotEmpty(t, value.ReferenceSchema, "Cache entry should have pre-converted ReferenceSchema string")
2017+
assert.Equal(t, string(value.RenderedInline), value.ReferenceSchema, "ReferenceSchema should match string conversion of RenderedInline")
20162018
return true
20172019
})
20182020
assert.Greater(t, count, 0, "Schema cache should have entries from request and response bodies")

0 commit comments

Comments
 (0)