github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/serde/avro/avro.go (about) 1 /** 2 * Copyright 2022 Confluent Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package avro 18 19 import ( 20 "github.com/actgardner/gogen-avro/v10/parser" 21 "github.com/actgardner/gogen-avro/v10/resolver" 22 "github.com/actgardner/gogen-avro/v10/schema" 23 "github.com/confluentinc/confluent-kafka-go/schemaregistry" 24 ) 25 26 func resolveAvroReferences(c schemaregistry.Client, schema schemaregistry.SchemaInfo, ns *parser.Namespace) (schema.AvroType, error) { 27 for _, ref := range schema.References { 28 metadata, err := c.GetSchemaMetadata(ref.Subject, ref.Version) 29 if err != nil { 30 return nil, err 31 } 32 info := schemaregistry.SchemaInfo{ 33 Schema: metadata.Schema, 34 SchemaType: metadata.SchemaType, 35 References: metadata.References, 36 } 37 _, err = resolveAvroReferences(c, info, ns) 38 if err != nil { 39 return nil, err 40 } 41 42 } 43 sType, err := ns.TypeForSchema([]byte(schema.Schema)) 44 if err != nil { 45 return nil, err 46 } 47 for _, def := range ns.Roots { 48 if err := resolver.ResolveDefinition(def, ns.Definitions); err != nil { 49 return nil, err 50 } 51 } 52 return sType, nil 53 }