Added all component schema to prevent allocations.

This function runs a lot and `syncMapToMap` is slow. The function is idepmotent so a cache prevents a lot of un-nessecary burn.
This commit is contained in:
quobix
2024-09-09 12:39:49 -04:00
parent d6e810ee8e
commit 781ec3c189
2 changed files with 10 additions and 1 deletions

View File

@@ -254,6 +254,7 @@ type SpecIndex struct {
allComponentSchemaDefinitions *sync.Map // all schemas found in components (openapi) or definitions (swagger).
securitySchemesNode *yaml.Node // components/securitySchemes node
allSecuritySchemes map[string]*Reference // all security schemes / definitions.
allComponentSchemas map[string]*Reference // all component schemas
requestBodiesNode *yaml.Node // components/requestBodies node
allRequestBodies map[string]*Reference // all request bodies
responsesNode *yaml.Node // components/responses node

View File

@@ -328,7 +328,15 @@ func (index *SpecIndex) GetAllReferenceSchemas() []*Reference {
// GetAllComponentSchemas will return all schemas defined in the components section of the document.
func (index *SpecIndex) GetAllComponentSchemas() map[string]*Reference {
return syncMapToMap[string, *Reference](index.allComponentSchemaDefinitions)
if index != nil && index.allComponentSchemas != nil {
return index.allComponentSchemas
}
if index != nil && index.allComponentSchemas == nil {
schemaMap := syncMapToMap[string, *Reference](index.allComponentSchemaDefinitions)
index.allComponentSchemas = schemaMap
return index.allComponentSchemas
}
return nil
}
// GetAllSecuritySchemes will return all security schemes / definitions found in the document.