Preserve terminal values during result lookup
This commit is contained in:
@@ -115,7 +115,9 @@ type schemaBuilder struct {
|
||||
building map[reflect.Type]bool
|
||||
journal []reflect.Type
|
||||
secrets SecretBinding
|
||||
lookup bool
|
||||
// lookup describes only the current container and its flattened inline fields.
|
||||
// Ordinary descendants are described only when navigation continues into them.
|
||||
lookup bool
|
||||
}
|
||||
|
||||
func (b *schemaBuilder) describe(current reflect.Type, path Path) (*typeDescriptor, *schemaIssue) {
|
||||
@@ -129,17 +131,15 @@ func (b *schemaBuilder) describe(current reflect.Type, path Path) (*typeDescript
|
||||
defer delete(b.building, current)
|
||||
|
||||
fail := func(code Code, message string) (*typeDescriptor, *schemaIssue) {
|
||||
// Lookup may reach unsupported values as terminals; they remain leaves.
|
||||
if b.lookup && (code == CodeSchemaUnsupportedType || code == CodeSchemaTextCodec) {
|
||||
descriptor.kind = descriptorInvalid
|
||||
return descriptor, nil
|
||||
}
|
||||
delete(b.cache, current)
|
||||
return nil, &schemaIssue{code: code, path: path.clone(), message: message}
|
||||
}
|
||||
|
||||
if current.Kind() == reflect.Pointer {
|
||||
descriptor.kind = descriptorPointer
|
||||
if b.lookup {
|
||||
return descriptor, nil
|
||||
}
|
||||
element, issue := b.describe(current.Elem(), path)
|
||||
if issue != nil {
|
||||
return nil, issue
|
||||
@@ -177,6 +177,9 @@ func (b *schemaBuilder) describe(current reflect.Type, path Path) (*typeDescript
|
||||
return fail(CodeSchemaUnsupportedType, "configuration maps must have string keys")
|
||||
}
|
||||
descriptor.kind = descriptorMap
|
||||
if b.lookup {
|
||||
return descriptor, nil
|
||||
}
|
||||
element, issue := b.describe(current.Elem(), path)
|
||||
if issue != nil {
|
||||
return nil, issue
|
||||
@@ -184,6 +187,9 @@ func (b *schemaBuilder) describe(current reflect.Type, path Path) (*typeDescript
|
||||
descriptor.element = element
|
||||
case reflect.Slice:
|
||||
descriptor.kind = descriptorSlice
|
||||
if b.lookup {
|
||||
return descriptor, nil
|
||||
}
|
||||
element, issue := b.describe(current.Elem(), path.Index(0))
|
||||
if issue != nil {
|
||||
return nil, issue
|
||||
@@ -192,6 +198,9 @@ func (b *schemaBuilder) describe(current reflect.Type, path Path) (*typeDescript
|
||||
case reflect.Array:
|
||||
descriptor.kind = descriptorArray
|
||||
descriptor.length = current.Len()
|
||||
if b.lookup {
|
||||
return descriptor, nil
|
||||
}
|
||||
element, issue := b.describe(current.Elem(), path.Index(0))
|
||||
if issue != nil {
|
||||
return nil, issue
|
||||
|
||||
Reference in New Issue
Block a user