Skip to content

Commit

Permalink
Merge branch '6.0.x' into 6.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rayokota committed Mar 8, 2021
2 parents c6cbb59 + e7352c3 commit 1206f43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.everit.json.schema.CombinedSchema;
import org.everit.json.schema.EmptySchema;
import org.everit.json.schema.EnumSchema;
import org.everit.json.schema.FalseSchema;
import org.everit.json.schema.NotSchema;
import org.everit.json.schema.NumberSchema;
import org.everit.json.schema.ObjectSchema;
Expand Down Expand Up @@ -158,8 +159,13 @@ static void compare(final Context ctx, Schema original, Schema update) {
}

if (!original.getClass().equals(update.getClass())) {
ctx.addDifference(Type.TYPE_CHANGED);
return;
// TrueSchema extends EmptySchema
if (original instanceof FalseSchema || update instanceof EmptySchema) {
return;
} else {
ctx.addDifference(Type.TYPE_CHANGED);
return;
}
}

try (Context.SchemaScope schemaScope = ctx.enterSchema(original)) {
Expand Down Expand Up @@ -197,13 +203,7 @@ static void compare(final Context ctx, Schema original, Schema update) {
}

private static Schema normalizeSchema(final Schema schema) {
if (schema instanceof EmptySchema) {
return ObjectSchema.builder()
.id(schema.getId())
.title(schema.getTitle())
.description(schema.getDescription())
.build();
} else if (schema instanceof ReferenceSchema) {
if (schema instanceof ReferenceSchema) {
return ((ReferenceSchema) schema).getReferredSchema();
} else {
return schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void testSchemaAddsProperties() {

final Schema second = SchemaLoader.load(new JSONObject(("{\"properties\": {}}")));
final List<Difference> changes = SchemaDiff.compare(first, second);
Assert.assertTrue(changes.isEmpty());
// Changing from empty schema to empty object schema is incompatible
Assert.assertFalse(changes.isEmpty());
}

public static String readFile(String fileName) {
Expand Down
26 changes: 26 additions & 0 deletions json-schema-provider/src/test/resources/diff-schema-examples.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
[
{
"description": "Anything can change to empty schema",
"original_schema": {
"properties": {
}
},
"update_schema": {
},
"changes": [
],
"compatible": true
},
{
"description": "Detect changes to id",
"original_schema": {
Expand Down Expand Up @@ -952,6 +964,8 @@
}
},
"update_schema": {
"dependencies": {
}
},
"changes": [
"DEPENDENCY_SCHEMA_REMOVED #/dependencies/foo"
Expand Down Expand Up @@ -1079,9 +1093,13 @@
{
"description": "Detect removed maxProperties",
"original_schema": {
"properties": {
},
"maxProperties": 1
},
"update_schema": {
"properties": {
}
},
"changes": [
"MAX_PROPERTIES_REMOVED #/maxProperties"
Expand Down Expand Up @@ -1117,9 +1135,13 @@
{
"description": "Detect removed minProperties",
"original_schema": {
"properties": {
},
"minProperties": 2
},
"update_schema": {
"properties": {
}
},
"changes": [
"MIN_PROPERTIES_REMOVED #/minProperties"
Expand Down Expand Up @@ -1524,9 +1546,13 @@
{
"description": "Detect added boolean additional properties",
"original_schema": {
"properties": {
},
"additionalProperties": false
},
"update_schema": {
"properties": {
}
},
"changes": [
"ADDITIONAL_PROPERTIES_ADDED #/additionalProperties"
Expand Down

0 comments on commit 1206f43

Please sign in to comment.