diff --git a/public/js/schema.js b/public/js/schema.js index f0243e0..591b170 100644 --- a/public/js/schema.js +++ b/public/js/schema.js @@ -233,12 +233,28 @@ AvroDoc.Schema = function (avrodoc, shared_types, schema_json, filename) { if (primitive_types.includes(name)) { return decorate({ type: name }); } - var type = named_types[qualifiedName(name, namespace)]; + + const qualifiedNameStr = qualifiedName(name, namespace); + const type = named_types[qualifiedNameStr]; if (type) { return type; - } else { - throw "Unknown type name " + JSON.stringify(name) + " at " + path; + } else if (hasOwnPropertyS(shared_types, qualifiedNameStr)) { + const sharedType = shared_types[qualifiedNameStr].find( + (sharedSchema) => sharedSchema.qualified_name === name + ); + + if (sharedType) { + return sharedType; + } else { + // TODO: Should also support arbitrary ordering of Avro schemas (currently + // this only works if the schema to be referred is parsed first) + throw `Shared schema ${qualifiedNameStr} does not have type ${JSON.stringify( + name + )}, referred to at ${path}`; + } } + + throw "Unknown type name " + JSON.stringify(name) + " at " + path; } /** diff --git a/schemata/reference_referent.avsc b/schemata/reference_referent.avsc new file mode 100644 index 0000000..d9541fc --- /dev/null +++ b/schemata/reference_referent.avsc @@ -0,0 +1,18 @@ +{ + "name": "ToBeReferred", + "type": "record", + "namespace": "com.example_referent", + "doc": "A simple object provided as a building block", + "fields": [ + { + "name": "value", + "type": "boolean", + "doc": "The value of the object to be referenced" + }, + { + "name": "history", + "type": "string", + "doc": "A history field detailing random information about the object" + } + ] +} diff --git a/schemata/reference_referrer.avsc b/schemata/reference_referrer.avsc new file mode 100644 index 0000000..9918ee5 --- /dev/null +++ b/schemata/reference_referrer.avsc @@ -0,0 +1,18 @@ +{ + "name": "TheReferrer", + "doc": "A complex object referencing object from another schemata", + "namespace": "com.example_referrer", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string", + "doc": "the name of the referrer object" + }, + { + "name": "externalObject", + "type": "com.example_referent.ToBeReferred", + "doc": "An object from another schemata" + } + ] +}