Skip to content

Commit 2f3ec03

Browse files
committed
Fix deprecation lint.
Also add an explicit reference to json-schema-core, since this imports it directly.
1 parent 15b01e7 commit 2f3ec03

File tree

11 files changed

+27
-18
lines changed

11 files changed

+27
-18
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ task sourcesJar(type: Jar, dependsOn: classes) {
127127
allprojects {
128128
gradle.projectsEvaluated {
129129
tasks.withType(JavaCompile) {
130-
options.compilerArgs << "-Xlint:all" << "-Xlint:-serial" << "-Xlint:-deprecation" << "-Werror"
130+
options.compilerArgs << "-Xlint:all" << "-Xlint:-serial" << "-Werror"
131131
}
132132
tasks.withType(Javadoc) {
133133
options.addStringOption('Xwerror', '-quiet')

project.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ project.ext {
3232
* List of dependencies
3333
*/
3434
dependencies {
35+
compile(group: "com.github.java-json-tools", name: "json-schema-core",
36+
version: "1.2.12");
3537
compile(group: "com.github.java-json-tools", name: "json-schema-validator",
3638
version: "2.2.12");
3739
compile(group: "org.apache.avro", name: "avro", version: "1.7.6") {
@@ -61,5 +63,6 @@ javadoc.options {
6163
links("https://fasterxml.github.com/jackson-annotations/javadoc/2.9/");
6264
links("https://www.javadoc.io/doc/com.google.guava/guava/28.1-android/");
6365
links("https://java-json-tools.github.io/msg-simple/");
66+
links("https://java-json-tools.github.io/json-schema-core/1.2.x/");
6467
links("https://java-json-tools.github.io/json-schema-validator/2.2.x/");
6568
}

src/main/java/com/github/fge/avro/Avro2JsonSchemaProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.github.fge.jsonschema.core.tree.CanonicalSchemaTree;
2727
import com.github.fge.jsonschema.core.tree.JsonTree;
2828
import com.github.fge.jsonschema.core.tree.SchemaTree;
29+
import com.github.fge.jsonschema.core.tree.key.SchemaKey;
2930
import org.apache.avro.AvroRuntimeException;
3031
import org.apache.avro.Schema;
3132

@@ -65,6 +66,6 @@ public SchemaTree rawProcess(final ProcessingReport report,
6566
AvroTranslators.getTranslator(avroType)
6667
.translate(avroSchema, tree, report);
6768

68-
return new CanonicalSchemaTree(tree.getBaseNode());
69+
return new CanonicalSchemaTree(SchemaKey.anonymousKey(), tree.getBaseNode());
6970
}
7071
}

src/main/java/com/github/fge/avro/MutableTree.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public boolean hasDefinition(final String name)
7272

7373
if (!baseNode.has("definitions")) {
7474
ret = false;
75-
baseNode.put("definitions", FACTORY.objectNode());
75+
baseNode.set("definitions", FACTORY.objectNode());
7676
}
7777

7878
final ObjectNode definitions = (ObjectNode) baseNode.get("definitions");
7979

8080
if (!definitions.has(name)) {
8181
ret = false;
82-
definitions.put(name, FACTORY.objectNode());
82+
definitions.set(name, FACTORY.objectNode());
8383
}
8484

8585
return ret;

src/main/java/com/github/fge/avro/translators/ArrayTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void translate(final Schema avroSchema, final MutableTree jsonSchema,
5151
final ObjectNode subSchema = FACTORY.objectNode();
5252
final Schema valuesSchema = avroSchema.getElementType();
5353

54-
jsonSchema.getCurrentNode().put("items", subSchema);
54+
jsonSchema.getCurrentNode().set("items", subSchema);
5555

5656
jsonSchema.setPointer(pwd.append("items"));
5757
AvroTranslators.getTranslator(valuesSchema.getType())

src/main/java/com/github/fge/avro/translators/EnumTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ protected void doTranslate(final Schema avroSchema,
4848
final ArrayNode enumValues = FACTORY.arrayNode();
4949
for (final String symbol: avroSchema.getEnumSymbols())
5050
enumValues.add(symbol);
51-
jsonSchema.getCurrentNode().put("enum", enumValues);
51+
jsonSchema.getCurrentNode().set("enum", enumValues);
5252
}
5353
}

src/main/java/com/github/fge/avro/translators/MapTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void translate(final Schema avroSchema, final MutableTree jsonSchema,
5151
final ObjectNode subSchema = FACTORY.objectNode();
5252
final Schema valuesSchema = avroSchema.getValueType();
5353

54-
jsonSchema.getCurrentNode().put("additionalProperties", subSchema);
54+
jsonSchema.getCurrentNode().set("additionalProperties", subSchema);
5555

5656
jsonSchema.setPointer(pwd.append("additionalProperties"));
5757
AvroTranslators.getTranslator(valuesSchema.getType())

src/main/java/com/github/fge/avro/translators/RecordTranslator.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected void doTranslate(final Schema avroSchema,
6060
if (fields.isEmpty()) {
6161
final ArrayNode node = FACTORY.arrayNode();
6262
node.add(FACTORY.objectNode());
63-
jsonSchema.getCurrentNode().put("enum", node);
63+
jsonSchema.getCurrentNode().set("enum", node);
6464
return;
6565
}
6666

@@ -72,12 +72,12 @@ protected void doTranslate(final Schema avroSchema,
7272
jsonSchema.setType(NodeType.OBJECT);
7373

7474
final ArrayNode required = FACTORY.arrayNode();
75-
jsonSchema.getCurrentNode().put("required", required);
75+
jsonSchema.getCurrentNode().set("required", required);
7676

7777
jsonSchema.getCurrentNode().put("additionalProperties", false);
7878

7979
final ObjectNode properties = FACTORY.objectNode();
80-
jsonSchema.getCurrentNode().put("properties", properties);
80+
jsonSchema.getCurrentNode().set("properties", properties);
8181

8282
String fieldName;
8383
Schema fieldSchema;
@@ -98,7 +98,7 @@ protected void doTranslate(final Schema avroSchema,
9898
required.add(fieldName);
9999
ptr = JsonPointer.of("properties", fieldName);
100100
propertyNode = FACTORY.objectNode();
101-
properties.put(fieldName, propertyNode);
101+
properties.set(fieldName, propertyNode);
102102
injectDefault(propertyNode, field);
103103
jsonSchema.setPointer(pwd.append(ptr));
104104
translator.translate(fieldSchema, jsonSchema, report);
@@ -119,7 +119,7 @@ private static void injectDefault(final ObjectNode propertyNode,
119119
*/
120120
try {
121121
final String s = OLD_MAPPER.writeValueAsString(value);
122-
propertyNode.put("default", JsonLoader.fromString(s));
122+
propertyNode.set("default", JsonLoader.fromString(s));
123123
} catch (IOException ignored) {
124124
// cannot happen
125125
}

src/main/java/com/github/fge/avro/translators/UnionTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void translate(final Schema avroSchema, final MutableTree jsonSchema,
4848
{
4949
final JsonPointer pwd = jsonSchema.getPointer();
5050
final ArrayNode schemas = FACTORY.arrayNode();
51-
jsonSchema.getCurrentNode().put("oneOf", schemas);
51+
jsonSchema.getCurrentNode().set("oneOf", schemas);
5252

5353
Schema schema;
5454
Schema.Type type;

src/main/java/com/github/fge/jsonschema2avro/writers/TypeUnionWriter.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import com.fasterxml.jackson.databind.node.ArrayNode;
2323
import com.fasterxml.jackson.databind.node.ObjectNode;
2424
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
25+
import com.github.fge.jsonschema.core.ref.JsonRef;
2526
import com.github.fge.jsonschema.core.report.ProcessingReport;
2627
import com.github.fge.jsonschema.core.tree.CanonicalSchemaTree;
2728
import com.github.fge.jsonschema.core.tree.SchemaTree;
29+
import com.github.fge.jsonschema.core.tree.key.SchemaKey;
2830
import com.github.fge.jsonschema.core.util.ValueHolder;
2931
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
3032
import 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

src/test/java/com/github/fge/jsonschema2avro/AvroWriterProcessorTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.github.fge.jsonschema.core.report.ProcessingReport;
2525
import com.github.fge.jsonschema.core.tree.CanonicalSchemaTree;
2626
import com.github.fge.jsonschema.core.tree.SchemaTree;
27+
import com.github.fge.jsonschema.core.tree.key.SchemaKey;
2728
import com.github.fge.jsonschema.core.util.ValueHolder;
2829
import com.google.common.collect.Lists;
2930
import org.apache.avro.Schema;
@@ -78,7 +79,7 @@ public final void JsonSchemasAreCorrectlyTranslated(final JsonNode schema,
7879
final JsonNode avro)
7980
throws ProcessingException
8081
{
81-
final SchemaTree tree = new CanonicalSchemaTree(schema);
82+
final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);
8283
final ValueHolder<SchemaTree> input = ValueHolder.hold("schema", tree);
8384
final Schema expected = new Schema.Parser().parse(avro.toString());
8485

0 commit comments

Comments
 (0)