Skip to content

Commit

Permalink
fix: oas to use any schema for json ast node (#1372)
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
patlo-iog authored Sep 23, 2024
1 parent 803be11 commit 95d328e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")
)
}

Expand All @@ -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) {
Expand Down Expand Up @@ -139,17 +139,17 @@ 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

extension (serviceEndpoint: 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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]
}

0 comments on commit 95d328e

Please sign in to comment.