From 95d328e3420d4731817a1f91c720e2833e9de362 Mon Sep 17 00:00:00 2001 From: patlo-iog Date: Mon, 23 Sep 2024 21:47:33 +0700 Subject: [PATCH] fix: oas to use any schema for json ast node (#1372) Signed-off-by: Pat Losoponkul --- .../api/http/codec/CirceJsonInterop.scala | 15 --------------- .../castor/controller/http/Service.scala | 18 +++++++++--------- .../PresentationExchangeTapirSchemas.scala | 4 +--- 3 files changed, 10 insertions(+), 27 deletions(-) delete mode 100644 cloud-agent/service/server/src/main/scala/org/hyperledger/identus/api/http/codec/CirceJsonInterop.scala diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/api/http/codec/CirceJsonInterop.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/api/http/codec/CirceJsonInterop.scala deleted file mode 100644 index 64269a575d..0000000000 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/api/http/codec/CirceJsonInterop.scala +++ /dev/null @@ -1,15 +0,0 @@ -package org.hyperledger.identus.api.http.codec - -import io.circe.Json as CirceJson -import org.hyperledger.identus.shared.json.JsonInterop -import sttp.tapir.json.zio.* -import sttp.tapir.Schema -import zio.json.* -import zio.json.ast.Json as ZioJson - -object CirceJsonInterop { - given encodeJson: JsonEncoder[CirceJson] = JsonEncoder[ZioJson].contramap(JsonInterop.toZioJsonAst) - given decodeJson: JsonDecoder[CirceJson] = JsonDecoder[ZioJson].map(JsonInterop.toCirceJsonAst) - given schemaJson: Schema[CirceJson] = - Schema.derived[ZioJson].map[CirceJson](js => Some(JsonInterop.toCirceJsonAst(js)))(JsonInterop.toZioJsonAst) -} diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/castor/controller/http/Service.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/castor/controller/http/Service.scala index 7229e911fc..44a1bfd788 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/castor/controller/http/Service.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/castor/controller/http/Service.scala @@ -1,15 +1,15 @@ package org.hyperledger.identus.castor.controller.http -import io.circe.Json -import org.hyperledger.identus.api.http.codec.CirceJsonInterop import org.hyperledger.identus.api.http.Annotation import org.hyperledger.identus.castor.controller.http.Service.annotations import org.hyperledger.identus.castor.core.model.{did as castorDomain, ProtoModelHelper} import org.hyperledger.identus.castor.core.model.did.w3c +import org.hyperledger.identus.shared.json.JsonInterop import org.hyperledger.identus.shared.utils.Traverse.* import sttp.tapir.Schema import sttp.tapir.Schema.annotations.{description, encodedExample} -import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder} +import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, EncoderOps, JsonDecoder, JsonEncoder} +import zio.json.ast.Json import scala.language.implicitConversions @@ -48,7 +48,7 @@ object Service { extends Annotation[Json]( description = "The service endpoint. Can contain multiple possible values as described in the [Create DID operation](https://github.com/input-output-hk/prism-did-method-spec/blob/main/w3c-spec/PRISM-method.md#create-did)", - example = Json.fromString("https://example.com") + example = Json.Str("https://example.com") ) } @@ -62,7 +62,7 @@ object Service { Service( id = service.id, `type` = service.`type`, - serviceEndpoint = ServiceEndpoint.fromJson(service.serviceEndpoint) + serviceEndpoint = ServiceEndpoint.fromJson(JsonInterop.toZioJsonAst(service.serviceEndpoint)) ) extension (service: Service) { @@ -139,9 +139,9 @@ object ServiceType { opaque type ServiceEndpoint = Json object ServiceEndpoint { - given encoder: JsonEncoder[ServiceEndpoint] = CirceJsonInterop.encodeJson - given decoder: JsonDecoder[ServiceEndpoint] = CirceJsonInterop.decodeJson - given schema: Schema[ServiceEndpoint] = CirceJsonInterop.schemaJson + given encoder: JsonEncoder[ServiceEndpoint] = Json.encoder + given decoder: JsonDecoder[ServiceEndpoint] = Json.decoder + given schema: Schema[ServiceEndpoint] = Schema.any[ServiceEndpoint] def fromJson(json: Json): ServiceEndpoint = json @@ -149,7 +149,7 @@ object ServiceEndpoint { def toDomain: Either[String, castorDomain.ServiceEndpoint] = { val stringEncoded = serviceEndpoint.asString match { case Some(s) => s - case None => serviceEndpoint.noSpaces + case None => serviceEndpoint.toJson } ProtoModelHelper.parseServiceEndpoint(stringEncoded) } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/prex/http/PresentationExchangeTapirSchemas.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/prex/http/PresentationExchangeTapirSchemas.scala index 91b129f5f2..e42fe2dcf9 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/prex/http/PresentationExchangeTapirSchemas.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/prex/http/PresentationExchangeTapirSchemas.scala @@ -1,9 +1,7 @@ package org.hyperledger.identus.pollux.prex.http import org.hyperledger.identus.pollux.prex.* -import sttp.tapir.json.zio.* import sttp.tapir.Schema -import zio.json.ast.Json import scala.language.implicitConversions @@ -20,5 +18,5 @@ object PresentationExchangeTapirSchemas { given Schema[Ldp] = Schema.derived given Schema[Field] = Schema.derived given Schema[JsonPathValue] = Schema.schemaForString.map[JsonPathValue](Some(_))(_.value) - given Schema[FieldFilter] = Schema.derived[Json].map[FieldFilter](Some(_))(_.asJsonZio) + given Schema[FieldFilter] = Schema.any[FieldFilter] }