From 6ab52453da12d84e4d73247dfacfc144c8f11a2a Mon Sep 17 00:00:00 2001 From: Nicholas Rempel <nbrempel@gmail.com> Date: Fri, 20 Sep 2019 15:16:25 -0700 Subject: [PATCH 1/5] Add swagger docs for store endpoint Signed-off-by: Nicholas Rempel <nbrempel@gmail.com> --- aries_cloudagent/messaging/credentials/routes.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/messaging/credentials/routes.py b/aries_cloudagent/messaging/credentials/routes.py index b52c5b5602..9c7fe33c93 100644 --- a/aries_cloudagent/messaging/credentials/routes.py +++ b/aries_cloudagent/messaging/credentials/routes.py @@ -2,6 +2,7 @@ import asyncio import json +from json.decoder import JSONDecodeError from aiohttp import web from aiohttp_apispec import docs, request_schema, response_schema @@ -69,6 +70,12 @@ class CredentialExchangeListSchema(Schema): results = fields.List(fields.Nested(CredentialExchangeSchema())) +class CredentialStoreRequestSchema(Schema): + """Request schema for sending a credential store admin message.""" + + credential_id = fields.Str(required=True) + + class CredentialSchema(Schema): """Result schema for a credential query.""" @@ -457,8 +464,11 @@ async def credential_exchange_store(request: web.BaseRequest): context = request.app["request_context"] outbound_handler = request.app["outbound_message_router"] - body = await request.json() - credential_id = body.get("credential_id") + try: + body = await request.json() + credential_id = body.get("credential_id") + except JSONDecodeError: + credential_id = None credential_exchange_id = request.match_info["id"] credential_exchange_record = await CredentialExchange.retrieve_by_id( From e5acadc2d9b795ee67499e90712b12059a146599 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel <nbrempel@gmail.com> Date: Fri, 20 Sep 2019 15:22:11 -0700 Subject: [PATCH 2/5] Apply swagger model to endpoint Signed-off-by: Nicholas Rempel <nbrempel@gmail.com> --- aries_cloudagent/messaging/credentials/routes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aries_cloudagent/messaging/credentials/routes.py b/aries_cloudagent/messaging/credentials/routes.py index 9c7fe33c93..60b2537e17 100644 --- a/aries_cloudagent/messaging/credentials/routes.py +++ b/aries_cloudagent/messaging/credentials/routes.py @@ -448,6 +448,7 @@ async def credential_exchange_issue(request: web.BaseRequest): @docs(tags=["credential_exchange *DEPRECATED*"], summary="Stores a received credential") +@request_schema(CredentialStoreRequestSchema()()) @response_schema(CredentialRequestResultSchema(), 200) async def credential_exchange_store(request: web.BaseRequest): """ From c37cf4ad7906aaa6a9d70e169b22e0de23f1c800 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel <nbrempel@gmail.com> Date: Fri, 20 Sep 2019 15:23:03 -0700 Subject: [PATCH 3/5] Fix typo Signed-off-by: Nicholas Rempel <nbrempel@gmail.com> --- aries_cloudagent/messaging/credentials/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/messaging/credentials/routes.py b/aries_cloudagent/messaging/credentials/routes.py index 60b2537e17..5e711811a1 100644 --- a/aries_cloudagent/messaging/credentials/routes.py +++ b/aries_cloudagent/messaging/credentials/routes.py @@ -448,7 +448,7 @@ async def credential_exchange_issue(request: web.BaseRequest): @docs(tags=["credential_exchange *DEPRECATED*"], summary="Stores a received credential") -@request_schema(CredentialStoreRequestSchema()()) +@request_schema(CredentialStoreRequestSchema()) @response_schema(CredentialRequestResultSchema(), 200) async def credential_exchange_store(request: web.BaseRequest): """ From facdad8e9e4cca0759e792b64bebe227f1f5d330 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel <nbrempel@gmail.com> Date: Fri, 20 Sep 2019 15:34:54 -0700 Subject: [PATCH 4/5] Empty string defaults to None Signed-off-by: Nicholas Rempel <nbrempel@gmail.com> --- aries_cloudagent/messaging/credentials/routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/messaging/credentials/routes.py b/aries_cloudagent/messaging/credentials/routes.py index 5e711811a1..69b5fa5409 100644 --- a/aries_cloudagent/messaging/credentials/routes.py +++ b/aries_cloudagent/messaging/credentials/routes.py @@ -73,7 +73,7 @@ class CredentialExchangeListSchema(Schema): class CredentialStoreRequestSchema(Schema): """Request schema for sending a credential store admin message.""" - credential_id = fields.Str(required=True) + credential_id = fields.Str(required=False) class CredentialSchema(Schema): @@ -466,7 +466,7 @@ async def credential_exchange_store(request: web.BaseRequest): outbound_handler = request.app["outbound_message_router"] try: - body = await request.json() + body = await request.json() or None credential_id = body.get("credential_id") except JSONDecodeError: credential_id = None From e5045af7e2a82805d0b3c1748c428925b7cc9bd4 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel <nbrempel@gmail.com> Date: Fri, 20 Sep 2019 16:27:50 -0700 Subject: [PATCH 5/5] Default to empty dict on empty strnig Signed-off-by: Nicholas Rempel <nbrempel@gmail.com> --- aries_cloudagent/messaging/credentials/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/messaging/credentials/routes.py b/aries_cloudagent/messaging/credentials/routes.py index 69b5fa5409..e5d1a1e7bf 100644 --- a/aries_cloudagent/messaging/credentials/routes.py +++ b/aries_cloudagent/messaging/credentials/routes.py @@ -466,7 +466,7 @@ async def credential_exchange_store(request: web.BaseRequest): outbound_handler = request.app["outbound_message_router"] try: - body = await request.json() or None + body = await request.json() or {} credential_id = body.get("credential_id") except JSONDecodeError: credential_id = None