1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-16 15:29:04 +00:00

Add ability to add multiple schematemplates per type

This commit is contained in:
Darren Shepherd
2021-03-02 07:30:00 -07:00
parent c1ea7b9626
commit 362617a677
2 changed files with 41 additions and 33 deletions

View File

@@ -132,30 +132,32 @@ func (c *Collection) applyTemplates(schema *types.APISchema) {
c.lock.RLock()
defer c.lock.RUnlock()
templates := []*Template{
templates := [][]*Template{
c.templates[schema.ID],
c.templates[fmt.Sprintf("%s/%s", attributes.Group(schema), attributes.Kind(schema))],
c.templates[""],
}
for _, t := range templates {
if t == nil {
continue
}
if schema.Formatter == nil {
schema.Formatter = t.Formatter
} else if t.Formatter != nil {
schema.Formatter = types.FormatterChain(t.Formatter, schema.Formatter)
}
if schema.Store == nil {
if t.StoreFactory == nil {
schema.Store = t.Store
} else {
schema.Store = t.StoreFactory(templates[2].Store)
for _, templates := range templates {
for _, t := range templates {
if t == nil {
continue
}
if schema.Formatter == nil {
schema.Formatter = t.Formatter
} else if t.Formatter != nil {
schema.Formatter = types.FormatterChain(t.Formatter, schema.Formatter)
}
if schema.Store == nil {
if t.StoreFactory == nil {
schema.Store = t.Store
} else {
schema.Store = t.StoreFactory(templates[2].Store)
}
}
if t.Customize != nil {
t.Customize(schema)
}
}
if t.Customize != nil {
t.Customize(schema)
}
}
}