From 6e112a0731f8214eb76ffb06de752298f2db0141 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 23 Feb 2024 11:36:22 +0100 Subject: [PATCH] Use new JsonSchemasProbe --- .../inspect/vc/EndorsementInspector.java | 21 +++++++++------ .../oneedtech/inspect/vc/OB30Inspector.java | 26 ++++++++++--------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/EndorsementInspector.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/EndorsementInspector.java index c0b761a..357faec 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/EndorsementInspector.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/EndorsementInspector.java @@ -2,7 +2,9 @@ package org.oneedtech.inspect.vc; import static java.lang.Boolean.TRUE; import static org.oneedtech.inspect.core.Inspector.Behavior.RESET_CACHES_ON_RUN; -import static org.oneedtech.inspect.core.probe.RunContext.Key.*; +import static org.oneedtech.inspect.core.probe.RunContext.Key.GENERATED_OBJECT_BUILDER; +import static org.oneedtech.inspect.core.probe.RunContext.Key.JACKSON_OBJECTMAPPER; +import static org.oneedtech.inspect.core.probe.RunContext.Key.JSONPATH_EVALUATOR; import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException; import static org.oneedtech.inspect.util.code.Defensives.checkNotNull; import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT; @@ -21,7 +23,6 @@ import org.oneedtech.inspect.core.probe.GeneratedObject; import org.oneedtech.inspect.core.probe.Probe; import org.oneedtech.inspect.core.probe.RunContext; import org.oneedtech.inspect.core.probe.json.JsonPathEvaluator; -import org.oneedtech.inspect.core.probe.json.JsonSchemaProbe; import org.oneedtech.inspect.core.report.Report; import org.oneedtech.inspect.core.report.ReportItems; import org.oneedtech.inspect.schema.JsonSchemaCache; @@ -39,6 +40,7 @@ import org.oneedtech.inspect.vc.probe.ExpirationProbe; import org.oneedtech.inspect.vc.probe.ExternalProofProbe; import org.oneedtech.inspect.vc.probe.InlineJsonSchemaProbe; import org.oneedtech.inspect.vc.probe.IssuanceProbe; +import org.oneedtech.inspect.vc.probe.JsonSchemasProbe; import org.oneedtech.inspect.vc.probe.RevocationListProbe; import org.oneedtech.inspect.vc.probe.TypePropertyProbe; import org.oneedtech.inspect.vc.util.CachingDocumentLoader; @@ -180,13 +182,16 @@ public class EndorsementInspector extends VCInspector implements SubInspector { if(broken(accumulator)) return abort(ctx, accumulator, probeCount); } - //canonical schema and inline schema + //canonical schema SchemaKey schema = endorsement.getSchemaKey().orElseThrow(); - for(Probe probe : List.of(new JsonSchemaProbe(schema), new InlineJsonSchemaProbe(schema))) { - probeCount++; - accumulator.add(probe.run(endorsement.getJson(), ctx)); - if(broken(accumulator)) return abort(ctx, accumulator, probeCount); - } + probeCount++; + accumulator.add(new JsonSchemasProbe(schema).run(endorsement, ctx)); + if(broken(accumulator)) return abort(ctx, accumulator, probeCount); + + // inline schema + probeCount++; + accumulator.add(new InlineJsonSchemaProbe(schema).run(endorsement.getJson(), ctx)); + if(broken(accumulator)) return abort(ctx, accumulator, probeCount); //credentialSubject probeCount++; diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java index e616709..3ee8523 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java @@ -3,7 +3,7 @@ package org.oneedtech.inspect.vc; import static java.lang.Boolean.TRUE; import static org.oneedtech.inspect.core.Inspector.Behavior.RESET_CACHES_ON_RUN; import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException; -import static org.oneedtech.inspect.util.code.Defensives.*; +import static org.oneedtech.inspect.util.code.Defensives.checkNotNull; import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT; import static org.oneedtech.inspect.vc.Credential.CREDENTIAL_KEY; import static org.oneedtech.inspect.vc.VerifiableCredential.REFRESH_SERVICE_MIME_TYPES; @@ -23,12 +23,10 @@ import org.oneedtech.inspect.core.probe.Probe; import org.oneedtech.inspect.core.probe.RunContext; import org.oneedtech.inspect.core.probe.RunContext.Key; import org.oneedtech.inspect.core.probe.json.JsonPathEvaluator; -import org.oneedtech.inspect.core.probe.json.JsonSchemaProbe; import org.oneedtech.inspect.core.report.Report; import org.oneedtech.inspect.core.report.ReportItems; import org.oneedtech.inspect.schema.JsonSchemaCache; import org.oneedtech.inspect.schema.SchemaKey; -import org.oneedtech.inspect.util.code.Defensives; import org.oneedtech.inspect.util.json.ObjectMapperCache; import org.oneedtech.inspect.util.resource.Resource; import org.oneedtech.inspect.util.resource.ResourceType; @@ -41,14 +39,15 @@ import org.oneedtech.inspect.vc.payload.SvgParser; import org.oneedtech.inspect.vc.probe.ContextPropertyProbe; import org.oneedtech.inspect.vc.probe.CredentialParseProbe; import org.oneedtech.inspect.vc.probe.CredentialSubjectProbe; +import org.oneedtech.inspect.vc.probe.EmbeddedProofProbe; +import org.oneedtech.inspect.vc.probe.EvidenceProbe; import org.oneedtech.inspect.vc.probe.ExpirationProbe; +import org.oneedtech.inspect.vc.probe.ExternalProofProbe; import org.oneedtech.inspect.vc.probe.InlineJsonSchemaProbe; import org.oneedtech.inspect.vc.probe.IssuanceProbe; import org.oneedtech.inspect.vc.probe.IssuerProbe; -import org.oneedtech.inspect.vc.probe.EmbeddedProofProbe; -import org.oneedtech.inspect.vc.probe.EvidenceProbe; +import org.oneedtech.inspect.vc.probe.JsonSchemasProbe; import org.oneedtech.inspect.vc.probe.RevocationListProbe; -import org.oneedtech.inspect.vc.probe.ExternalProofProbe; import org.oneedtech.inspect.vc.probe.TypePropertyProbe; import org.oneedtech.inspect.vc.util.CachingDocumentLoader; @@ -163,13 +162,16 @@ public class OB30Inspector extends VCInspector implements SubInspector { if(broken(accumulator)) return abort(ctx, accumulator, probeCount); } - //canonical schema and inline schemata + //canonical schema SchemaKey schema = ob.getSchemaKey().orElseThrow(); - for(Probe probe : List.of(new JsonSchemaProbe(schema), new InlineJsonSchemaProbe(schema))) { - probeCount++; - accumulator.add(probe.run(ob.getJson(), ctx)); - if(broken(accumulator)) return abort(ctx, accumulator, probeCount); - } + probeCount++; + accumulator.add(new JsonSchemasProbe(schema).run(ob, ctx)); + if(broken(accumulator)) return abort(ctx, accumulator, probeCount); + + // inline schema + probeCount++; + accumulator.add(new InlineJsonSchemaProbe(schema).run(ob.getJson(), ctx)); + if(broken(accumulator)) return abort(ctx, accumulator, probeCount); //credentialSubject probeCount++;