Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get subschemas of CombinedSchema in insertion order #519

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/src/main/java/org/everit/json/schema/CombinedSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public static Builder oneOf(Collection<Schema> schemas) {

private final boolean synthetic;

private final Collection<Schema> orderedSubschemas;

private final Collection<Schema> subschemas;

private final ValidationCriterion criterion;
Expand All @@ -168,6 +170,7 @@ public CombinedSchema(Builder builder) {
super(builder);
this.synthetic = builder.synthetic;
this.criterion = requireNonNull(builder.criterion, "criterion cannot be null");
this.orderedSubschemas = builder.subschemas;
this.subschemas = sortByCombinedFirst(requireNonNull(builder.subschemas, "subschemas cannot be null"));
}

Expand All @@ -191,6 +194,14 @@ public ValidationCriterion getCriterion() {
return criterion;
}

/**
* Returns the subschemas in the order they were added.
* @return the subschemas in insertion order
*/
public Collection<Schema> getOrderedSubschemas() {
return orderedSubschemas;
}

public Collection<Schema> getSubschemas() {
return subschemas;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public void subschemasSort() {
assertEquals(booleanSchema2, subschemas[5]);
assertEquals(emptySchema2, subschemas[6]);
assertEquals(nullSchema2, subschemas[7]);

subschemas = subject.getOrderedSubschemas().toArray();

assertEquals(8, subschemas.length);
assertEquals(nullSchema1, subschemas[0]);
assertEquals(emptySchema1, subschemas[1]);
assertEquals(booleanSchema1, subschemas[2]);
assertEquals(subcombined1, subschemas[3]);
assertEquals(booleanSchema2, subschemas[4]);
assertEquals(emptySchema2, subschemas[5]);
assertEquals(nullSchema2, subschemas[6]);
assertEquals(subcombined2, subschemas[7]);
}

@Test
Expand Down Expand Up @@ -172,7 +184,7 @@ public void reportCauses() {
public void equalsVerifier() {
EqualsVerifier.forClass(CombinedSchema.class)
.withRedefinedSuperclass()
.withIgnoredFields("schemaLocation", "location")
.withIgnoredFields("schemaLocation", "location", "orderedSubschemas")
.suppress(Warning.STRICT_INHERITANCE)
.verify();
}
Expand Down