Skip to content

Commit

Permalink
fix: openapi requests and responses for vc routes
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Dec 10, 2024
1 parent 7fc0e2f commit a311511
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
10 changes: 7 additions & 3 deletions acapy_agent/vc/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ async def list_credentials_route(request: web.BaseRequest):
holder = context.inject(VCHolder)
try:
search = holder.search_credentials()
records = [record.serialize()["cred_value"] for record in await search.fetch()]
records = {
"results": [
record.serialize()["cred_value"] for record in await search.fetch()
]
}
return web.json_response(records, status=200)
except (StorageError, StorageNotFoundError) as err:
return web.json_response({"message": err.roll_up}, status=400)
Expand Down Expand Up @@ -133,7 +137,7 @@ async def verify_credential_route(request: web.BaseRequest):


@docs(tags=["vc-api"], summary="Store a credential")
@request_schema(web_schemas.VerifyCredentialRequest())
@request_schema(web_schemas.StoreCredentialRequest())
@response_schema(web_schemas.StoreCredentialResponse(), 200, description="")
@tenant_authentication
async def store_credential_route(request: web.BaseRequest):
Expand All @@ -156,7 +160,7 @@ async def store_credential_route(request: web.BaseRequest):
options = LDProofVCOptions.deserialize(options)

await manager.verify_credential(vc)
await manager.store_credential(vc, options, cred_id)
await manager.store_credential(vc, cred_id)

return web.json_response({"credentialId": cred_id}, status=200)

Expand Down
5 changes: 3 additions & 2 deletions acapy_agent/vc/vc_ld/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ async def issue(
async def store_credential(
self,
vc: VerifiableCredential,
options: LDProofVCOptions,
cred_id: Optional[str] = None,
) -> VerifiableCredential:
) -> VCRecord:
"""Store a verifiable credential."""

# Saving expanded type as a cred_tag
Expand Down Expand Up @@ -437,6 +436,8 @@ async def store_credential(

await vc_holder.store_credential(vc_record)

return vc_record

async def verify_credential(
self, vc: VerifiableCredential
) -> DocumentVerificationResult:
Expand Down
8 changes: 7 additions & 1 deletion acapy_agent/vc/vc_ld/models/web_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ListCredentialsResponse(OpenAPISchema):
"""Response schema for listing credentials."""

results = [fields.Nested(VerifiableCredentialSchema)]
results = fields.List(fields.Nested(VerifiableCredentialSchema))


class FetchCredentialResponse(OpenAPISchema):
Expand Down Expand Up @@ -47,6 +47,12 @@ class VerifyCredentialResponse(OpenAPISchema):
results = fields.Nested(PresentationVerificationResultSchema)


class StoreCredentialRequest(OpenAPISchema):
"""Request schema for verifying an LDP VP."""

verifiableCredential = fields.Nested(VerifiableCredentialSchema)


class StoreCredentialResponse(OpenAPISchema):
"""Request schema for verifying an LDP VP."""

Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/vc/vc_ld/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async def test_store(
self.vc.issuer = did.did
self.options.proof_type = Ed25519Signature2018.signature_type
cred = await self.manager.issue(self.vc, self.options)
await self.manager.store_credential(cred, self.options, TEST_UUID)
await self.manager.store_credential(cred, TEST_UUID)
async with self.profile.session() as session:
holder = session.inject(VCHolder)
record = await holder.retrieve_credential_by_id(record_id=TEST_UUID)
Expand Down

0 comments on commit a311511

Please sign in to comment.