22
22
import com .fasterxml .jackson .databind .node .ArrayNode ;
23
23
import com .fasterxml .jackson .databind .node .ObjectNode ;
24
24
import com .github .fge .jsonschema .core .exceptions .ProcessingException ;
25
+ import com .github .fge .jsonschema .core .ref .JsonRef ;
25
26
import com .github .fge .jsonschema .core .report .ProcessingReport ;
26
27
import com .github .fge .jsonschema .core .tree .CanonicalSchemaTree ;
27
28
import com .github .fge .jsonschema .core .tree .SchemaTree ;
29
+ import com .github .fge .jsonschema .core .tree .key .SchemaKey ;
28
30
import com .github .fge .jsonschema .core .util .ValueHolder ;
29
31
import com .github .fge .jsonschema2avro .AvroWriterProcessor ;
30
32
import com .google .common .collect .Lists ;
@@ -53,17 +55,19 @@ protected Schema generate(final AvroWriterProcessor writer,
53
55
{
54
56
// In such a union, there cannot be embedded unions so we need not care
55
57
// here
58
+ final JsonRef context = tree .getContext ();
56
59
final JsonNode node = tree .getNode ();
57
60
final List <Schema > schemas = Lists .newArrayList ();
58
61
59
- for (final ValueHolder <SchemaTree > holder : expand (node ))
62
+ for (final ValueHolder <SchemaTree > holder : expand (context , node ))
60
63
schemas .add (writer .process (report , holder ).getValue ());
61
64
62
65
return Schema .createUnion (schemas );
63
66
}
64
67
65
- private static List <ValueHolder <SchemaTree >> expand (final JsonNode node )
68
+ private static List <ValueHolder <SchemaTree >> expand (final JsonRef context , final JsonNode node )
66
69
{
70
+ final SchemaKey key = SchemaKey .forJsonRef (context );
67
71
final ObjectNode common = node .deepCopy ();
68
72
final ArrayNode typeNode = (ArrayNode ) common .remove ("type" );
69
73
@@ -74,8 +78,8 @@ private static List<ValueHolder<SchemaTree>> expand(final JsonNode node)
74
78
75
79
for (final JsonNode element : typeNode ) {
76
80
schema = common .deepCopy ();
77
- schema .put ("type" , element );
78
- tree = new CanonicalSchemaTree (schema );
81
+ schema .set ("type" , element );
82
+ tree = new CanonicalSchemaTree (key , schema );
79
83
ret .add (ValueHolder .hold ("schema" , tree ));
80
84
}
81
85
0 commit comments