From fb1592d32731d8c2a63b1582c7d600b7780837f1 Mon Sep 17 00:00:00 2001 From: Benjamin Voiturier Date: Fri, 12 Jan 2024 14:59:53 +0100 Subject: [PATCH] fix(prism-agent): fallback to OEA proprietary format for JWT VC schema when spec-format parsing fails Signed-off-by: Benjamin Voiturier --- .../core/model/schema/CredentialSchema.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala index 3c8ef9f296..1881137ca9 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialSchema.scala @@ -125,10 +125,19 @@ object CredentialSchema { for { uri <- ZIO.attempt(new URI(schemaId)).mapError(t => URISyntaxError(t.getMessage)) content <- uriDereferencer.dereference(uri).mapError(err => UnexpectedError(err.toString)) - jsonSchema <- ZIO + json <- ZIO .fromEither(content.fromJson[Json]) - .mapError(error => CredentialSchemaError.CredentialSchemaParsingError(s"Json Schema parsing error: $error")) - schemaValidator <- JsonSchemaValidatorImpl.from(jsonSchema).mapError(SchemaError.apply) + .mapError(error => + CredentialSchemaError.CredentialSchemaParsingError(s"Failed to parse resolved schema content as Json: $error") + ) + schemaValidator <- JsonSchemaValidatorImpl + .from(json) + .orElse( + ZIO + .fromEither(json.as[CredentialSchema]) + .mapError(error => CredentialSchemaParsingError(s"Failed to parse schema content as Json or OEA: $error")) + .flatMap(cs => JsonSchemaValidatorImpl.from(cs.schema).mapError(SchemaError.apply)) + ) _ <- schemaValidator.validate(claims).mapError(SchemaError.apply) } yield () }