Added related validation test, fixing fullValidate
This commit is contained in:
@@ -201,7 +201,7 @@ public class Assertion extends Credential {
|
||||
new Validation.Builder().name("image").type(ValueType.IMAGE).build(),
|
||||
new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(),
|
||||
new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Assertion).many(true).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Assertion).many(true).fullValidate(false).build(),
|
||||
new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build()
|
||||
))
|
||||
.put(Type.BadgeClass, List.of(
|
||||
@@ -216,7 +216,7 @@ public class Assertion extends Credential {
|
||||
new Validation.Builder().name("tags").type(ValueType.TEXT).many(true).build(),
|
||||
new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(),
|
||||
new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.BadgeClass).many(true).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.BadgeClass).many(true).fullValidate(false).build(),
|
||||
new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build()
|
||||
))
|
||||
.put(Type.AlignmentObject, List.of(
|
||||
@@ -241,13 +241,13 @@ public class Assertion extends Credential {
|
||||
.put(Type.Endorsement, List.of(
|
||||
new Validation.Builder().name("id").type(ValueType.IRI).required(true).build(),
|
||||
new Validation.Builder().name("type").type(ValueType.RDF_TYPE).required(true).many(true).mustContainOneType(List.of(Type.Endorsement)).build(),
|
||||
new Validation.Builder().name("claim").type(ValueType.ID).required(true).expectedTypes(List.of(Type.EndorsementClaim, Type.Endorsement)).build(),
|
||||
new Validation.Builder().name("claim").type(ValueType.ID).required(true).expectedTypes(List.of(Type.EndorsementClaim, Type.Endorsement)).fullValidate(false).build(),
|
||||
new Validation.Builder().name("issuedOn").type(ValueType.DATETIME).required(true).build(),
|
||||
new Validation.Builder().name("issuer").type(ValueType.ID).expectedType(Type.Profile).fetch(true).required(true).build(),
|
||||
new Validation.Builder().name("verification").build(),
|
||||
new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(),
|
||||
new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Endorsement).many(true).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Endorsement).many(true).fullValidate(false).build(),
|
||||
new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build()
|
||||
))
|
||||
.put(Type.EndorsementClaim, List.of(
|
||||
@@ -303,7 +303,7 @@ public class Assertion extends Credential {
|
||||
new Validation.Builder().name("id").type(ValueType.ISSUER).messageLevel(MessageLevel.Warning).build(),
|
||||
new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(),
|
||||
new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Issuer).many(true).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Issuer).many(true).fullValidate(false).build(),
|
||||
new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build()
|
||||
))
|
||||
.put(Type.Profile, List.of(
|
||||
@@ -320,7 +320,7 @@ public class Assertion extends Credential {
|
||||
new Validation.Builder().name("id").type(ValueType.ISSUER).messageLevel(MessageLevel.Warning).build(),
|
||||
new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(),
|
||||
new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Profile).many(true).build(),
|
||||
new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Profile).many(true).fullValidate(false).build(),
|
||||
new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build()
|
||||
))
|
||||
.put(Type.RevocationList, List.of(
|
||||
|
||||
@@ -122,6 +122,7 @@ public class Validation {
|
||||
this.prerequisites = new ArrayList<>();
|
||||
this.expectedTypes = new ArrayList<>();
|
||||
this.messageLevel = MessageLevel.Error;
|
||||
this.fullValidate = true; // by default, full validation
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
|
||||
+4
-4
@@ -40,11 +40,11 @@ public class ValidationPropertyProbe extends PropertyProbe {
|
||||
protected final boolean fullValidate; // TODO: fullValidate
|
||||
|
||||
public ValidationPropertyProbe(Validation validation) {
|
||||
this(ID, validation, false);
|
||||
this(ID, validation, true);
|
||||
}
|
||||
|
||||
public ValidationPropertyProbe(String id, Validation validation) {
|
||||
this(ID, validation, false);
|
||||
this(ID, validation, true);
|
||||
}
|
||||
|
||||
public ValidationPropertyProbe(Validation validation, boolean fullValidate) {
|
||||
@@ -60,10 +60,10 @@ public class ValidationPropertyProbe extends PropertyProbe {
|
||||
|
||||
@Override
|
||||
protected ReportItems reportForNonExistentProperty(JsonNode node, RunContext ctx) {
|
||||
if (validation.isRequired()) {
|
||||
if (fullValidate && validation.isRequired()) {
|
||||
return error("Required property " + validation.getName() + " not present in " + node.toPrettyString(), ctx);
|
||||
} else {
|
||||
// optional property
|
||||
// optional property or not doing full validation
|
||||
return success(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.oneedtech.inspect.vc.Validation;
|
||||
*/
|
||||
public class ValidationPropertyProbeFactory {
|
||||
public static ValidationPropertyProbe of(Validation validation) {
|
||||
return of(validation, false);
|
||||
return of(validation, true);
|
||||
}
|
||||
|
||||
public static ValidationPropertyProbe of(Validation validation, boolean fullValidate) {
|
||||
|
||||
+4
@@ -39,6 +39,10 @@ public class ValidationRdfTypePropertyProbe extends ValidationPropertyProbe {
|
||||
}
|
||||
}
|
||||
|
||||
// if we're not doing a full validation and it's not and id field, pass
|
||||
if (!fullValidate && !validation.getName().equals("id")) {
|
||||
return success(ctx);
|
||||
}
|
||||
return error("Required property " + validation.getName() + " not present in " + node.toPrettyString(), ctx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user