2222import com .fasterxml .jackson .databind .node .ArrayNode ;
2323import com .fasterxml .jackson .databind .node .ObjectNode ;
2424import com .github .fge .jsonschema .core .exceptions .ProcessingException ;
25+ import com .github .fge .jsonschema .core .ref .JsonRef ;
2526import com .github .fge .jsonschema .core .report .ProcessingReport ;
2627import com .github .fge .jsonschema .core .tree .CanonicalSchemaTree ;
2728import com .github .fge .jsonschema .core .tree .SchemaTree ;
29+ import com .github .fge .jsonschema .core .tree .key .SchemaKey ;
2830import com .github .fge .jsonschema .core .util .ValueHolder ;
2931import com .github .fge .jsonschema2avro .AvroWriterProcessor ;
3032import com .google .common .collect .Lists ;
@@ -53,17 +55,19 @@ protected Schema generate(final AvroWriterProcessor writer,
5355 {
5456 // In such a union, there cannot be embedded unions so we need not care
5557 // here
58+ final JsonRef context = tree .getContext ();
5659 final JsonNode node = tree .getNode ();
5760 final List <Schema > schemas = Lists .newArrayList ();
5861
59- for (final ValueHolder <SchemaTree > holder : expand (node ))
62+ for (final ValueHolder <SchemaTree > holder : expand (context , node ))
6063 schemas .add (writer .process (report , holder ).getValue ());
6164
6265 return Schema .createUnion (schemas );
6366 }
6467
65- private static List <ValueHolder <SchemaTree >> expand (final JsonNode node )
68+ private static List <ValueHolder <SchemaTree >> expand (final JsonRef context , final JsonNode node )
6669 {
70+ final SchemaKey key = SchemaKey .forJsonRef (context );
6771 final ObjectNode common = node .deepCopy ();
6872 final ArrayNode typeNode = (ArrayNode ) common .remove ("type" );
6973
@@ -74,8 +78,8 @@ private static List<ValueHolder<SchemaTree>> expand(final JsonNode node)
7478
7579 for (final JsonNode element : typeNode ) {
7680 schema = common .deepCopy ();
77- schema .put ("type" , element );
78- tree = new CanonicalSchemaTree (schema );
81+ schema .set ("type" , element );
82+ tree = new CanonicalSchemaTree (key , schema );
7983 ret .add (ValueHolder .hold ("schema" , tree ));
8084 }
8185
0 commit comments