1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-18 16:35:19 +00:00

Allow circular types to be imported

This commit is contained in:
Darren Shepherd
2018-12-17 15:40:55 -07:00
parent a20e5736da
commit 77a8edaa99
2 changed files with 15 additions and 5 deletions

View File

@@ -83,6 +83,9 @@ func (s *Schemas) newSchemaFromType(version *APIVersion, t reflect.Type, typeNam
CollectionActions: map[string]Action{},
}
s.processingTypes[t] = schema
defer delete(s.processingTypes, t)
if err := s.readFields(schema, t); err != nil {
return nil, err
}
@@ -148,6 +151,11 @@ func (s *Schemas) importType(version *APIVersion, t reflect.Type, overrides ...r
return existing, nil
}
if s, ok := s.processingTypes[t]; ok {
logrus.Debugf("Returning half built schema %s for %v", typeName, t)
return s, nil
}
logrus.Debugf("Inspecting schema %s for %v", typeName, t)
schema, err := s.newSchemaFromType(version, t, typeName)

View File

@@ -29,6 +29,7 @@ type BackReference struct {
type Schemas struct {
sync.Mutex
processingTypes map[reflect.Type]*Schema
typeNames map[reflect.Type]string
schemasByPath map[string]map[string]*Schema
mappers map[string]map[string][]Mapper
@@ -44,11 +45,12 @@ type Schemas struct {
func NewSchemas() *Schemas {
return &Schemas{
typeNames: map[reflect.Type]string{},
schemasByPath: map[string]map[string]*Schema{},
mappers: map[string]map[string][]Mapper{},
references: map[string][]BackReference{},
embedded: map[string]*Schema{},
processingTypes: map[reflect.Type]*Schema{},
typeNames: map[reflect.Type]string{},
schemasByPath: map[string]map[string]*Schema{},
mappers: map[string]map[string][]Mapper{},
references: map[string][]BackReference{},
embedded: map[string]*Schema{},
}
}