Skip to content

Commit

Permalink
add contentType to ResolutionMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Losoponkul committed Mar 20, 2023
1 parent ff0c800 commit 4e75d01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions prism-agent/service/api/http/castor/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ components:
type: string
description: Resolution error constant according to [DID spec registries](https://www.w3.org/TR/did-spec-registries/#error)
example: invalidDid
contentType:
type: string
description: The media type of the returned DID document
example: application/did+ld+json

VerificationMethod:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
given RootJsonFormat[DIDOperationResponse] = jsonFormat1(DIDOperationResponse.apply)
given RootJsonFormat[DidOperationSubmission] = jsonFormat2(DidOperationSubmission.apply)
given RootJsonFormat[DIDResponse] = jsonFormat2(DIDResponse.apply)
given RootJsonFormat[DIDResolutionMetadata] = jsonFormat1(DIDResolutionMetadata.apply)
given RootJsonFormat[DIDResolutionMetadata] = jsonFormat2(DIDResolutionMetadata.apply)
given RootJsonFormat[ErrorResponse] = jsonFormat5(ErrorResponse.apply)
given RootJsonFormat[ManagedDID] = jsonFormat3(ManagedDID.apply)
given RootJsonFormat[ManagedDIDPage] = jsonFormat6(ManagedDIDPage.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class DIDApiServiceImpl(service: DIDService)(using runtime: Runtime[Any])
result <- makeW3CResolver(service)(didRef).either
resolutionResult = result.fold(_.toOASResolutionResult, _.toOASResolutionResult)
resolutionError = result.swap.toOption
} yield buildResolutionResp(resolutionResult, resolutionError)
} yield buildHttpBindingResponse(resolutionResult, resolutionError)

onZioSuccess(result)(identity)
}

// Return response dynamically based on "Content-Type" negotiation
// according to https://w3c-ccg.github.io/did-resolution/#bindings-https
private def buildResolutionResp(
private def buildHttpBindingResponse(
resolutionResult: OASModelPatches.DIDResolutionResult,
resolutionError: Option[DIDResolutionErrorRepr]
): Route = {
Expand All @@ -67,6 +67,11 @@ class DIDApiServiceImpl(service: DIDService)(using runtime: Runtime[Any])
Marshaller.StringMarshaller
.wrap(CustomMediaTypes.`application/ld+json;did-resolution`)(CompactPrinter)
.compose(writer.write)
.compose { result =>
result.copy(didResolutionMetadata =
result.didResolutionMetadata.copy(contentType = Some(CustomMediaTypes.`application/did+ld+json`.value))
)
}
}

given ToEntityMarshaller[OASModelPatches.DIDResolutionResult] =
Expand Down

0 comments on commit 4e75d01

Please sign in to comment.