The call I am making that raises this error is:
\n openapi_response = RequestsOpenAPIResponse(api_response)\n openapi_request = RequestsOpenAPIRequest(api_response.request)\n openapi.validate_response(openapi_request, openapi_response)\nWhere api_response is a requests.models.Response:
(Pdb) type(api_response)\n<class 'requests.models.Response'>\n(Pdb) api_response.content\nb'\\n \\n \\n \\n {\"entry\":[{\"fullUrl\":\"https://internal-dev.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/47CD795E\",\"resource\":{\"id\":\"47CD795E\",\"identifier\":[{\"system\":\"https://fhir.nhs.uk/Id/nhs-number\",\"value\":\"9730675929\"}],\"patient\":{\"identifier\":{\"system\":\"https://fhir.nhs.uk/Id/nhs-number\",\"value\":\"9730676399\"},\"type\":\"Patient\"},\"relationship\":[{\"coding\":[{\"code\":\"MTH\",\"display\":\"mother\",\"system\":\"http://terminology.hl7.org/CodeSystem/v3-RoleCode\"}]}],\"resourceType\":\"RelatedPerson\"},\"search\":{\"mode\":\"match\"}}],\"link\":[{\"relation\":\"self\",\"url\":\"https://internal-dev.api.service.nhs.uk/validated-relationships-service-api/FHIR/R4/RelatedPerson?identifier=9730675929&patient%3Aidentifier=9730676399\"}],\"timestamp\":\"2024-04-24T10:05:26+00:00\",\"total\":1,\"type\":\"searchset\",\"resourceType\":\"Bundle\"}\\n'\nSo it looks like openapi-core is expecting a dict but is getting bytes:
\n openapi-core/openapi_core/casting/schemas/casters.py\n
\n\n Lines 113 to 114\n in\n 99af2d3\n
\n| \n | if not isinstance(value, dict): | \n
| \n | raise CastError(value, self.schema[\"type\"]) | \n
(Pdb) openapi_response.data\nb'\\n \\n \\n \\n {\"entry\":[{\"fullUrl\":\"https://internal-dev.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/47CD795E\",\"resource\":{\"id\":\"47CD795E\",\"identifier\":[{\"system\":\"https://fhir.nhs.uk/Id/nhs-number\",\"value\":\"9730675929\"}],\"patient\":{\"identifier\":{\"system\":\"https://fhir.nhs.uk/Id/nhs-number\",\"value\":\"9730676399\"},\"type\":\"Patient\"},\"relationship\":[{\"coding\":[{\"code\":\"MTH\",\"display\":\"mother\",\"system\":\"http://terminology.hl7.org/CodeSystem/v3-RoleCode\"}]}],\"resourceType\":\"RelatedPerson\"},\"search\":{\"mode\":\"match\"}}],\"link\":[{\"relation\":\"self\",\"url\":\"https://internal-dev.api.service.nhs.uk/validated-relationships-service-api/FHIR/R4/RelatedPerson?identifier=9730675929&patient%3Aidentifier=9730676399\"}],\"timestamp\":\"2024-04-24T10:15:31+00:00\",\"total\":1,\"type\":\"searchset\",\"resourceType\":\"Bundle\"}\\n'\n(Pdb) type(openapi_response.data)\n<class 'bytes'>\nI have worked round this by subclassing RequestsOpenAPIResponse so the data attribute returns a dict which works for me but I'd like to understand why I'm seeing this issue in the first place and what, if anything, I am doing wrong.
Thanks
","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Exactly that; you can use the same function as standard one
\nfrom openapi_core.deserializing.media_types.util import json_loads-
|
Hi, I'm using openapi-core to validate responses against this OpenAPI schema: https://digital.nhs.uk/restapi/oas/573240 The error I'm getting is this: The call I am making that raises this error is: Where So it looks like openapi-core is expecting a openapi-core/openapi_core/casting/schemas/casters.py Lines 113 to 114 in 99af2d3 I have worked round this by subclassing Thanks |
Beta Was this translation helpful? Give feedback.
-
|
Probably you don't have registered proper deserializer. What schema and content-type are defined for the response in your spec? |
Beta Was this translation helpful? Give feedback.
Exactly that; you can use the same function as standard one