diff --git a/types/reflection.go b/types/reflection.go index 05b4ea58..33295c32 100644 --- a/types/reflection.go +++ b/types/reflection.go @@ -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) diff --git a/types/schemas.go b/types/schemas.go index 5d2d7d67..0e72a178 100644 --- a/types/schemas.go +++ b/types/schemas.go @@ -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{}, } }