Title: [Bug]: Does Not Support Binary Response Types · Issue #245 · python-openapi/openapi-schema-validator · GitHub
Open Graph Title: [Bug]: Does Not Support Binary Response Types · Issue #245 · python-openapi/openapi-schema-validator
X Title: [Bug]: Does Not Support Binary Response Types · Issue #245 · python-openapi/openapi-schema-validator
Description: Actual Behavior I hacked together the code below so that I could test this library in isolation, but for context we are using it inside of a Pyramid app. When I run the case below, I get the following exception: openapi_core.validation.r...
Open Graph Description: Actual Behavior I hacked together the code below so that I could test this library in isolation, but for context we are using it inside of a Pyramid app. When I run the case below, I get the follow...
X Description: Actual Behavior I hacked together the code below so that I could test this library in isolation, but for context we are using it inside of a Pyramid app. When I run the case below, I get the follow...
Opengraph URL: https://github.com/python-openapi/openapi-schema-validator/issues/245
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Does Not Support Binary Response Types","articleBody":"### Actual Behavior\r\n\r\nI hacked together the code below so that I could test this library in isolation, but for context we are using it inside of a Pyramid app. When I run the case below, I get the following exception:\r\n\r\n```\r\nopenapi_core.validation.response.exceptions.InvalidData: InvalidData: Value b'\u003cpdf_content\u003e' not valid for schema of type string: (\u003cValidationError: \"b'\u003cpdf_content\u003e' is not of type 'string'\"\u003e,)\r\n```\r\n\r\nIf I then try to wrap it inside of a `str()`, I get `is not of type 'binary'` so I believe there is an issue with the formatter understanding the bytes as a string.\r\n\r\n\r\n### Expected Behavior\r\n\r\nIf I return a binary object (pdf file) it should pass validation.\r\n\r\n### Steps to Reproduce\r\n\r\n\r\n```python\r\nimport typing as t\r\n\r\nfrom openapi_core import OpenAPI\r\nfrom openapi_core.validation.request.datatypes import RequestParameters\r\n\r\n\r\nclass OpenAPIRequest:\r\n def __init__(self) -\u003e None:\r\n self.parameters = RequestParameters(\r\n path={},\r\n query={},\r\n header={},\r\n cookie={},\r\n )\r\n\r\n @property\r\n def host_url(self) -\u003e str:\r\n return \"https://example.com\"\r\n\r\n @property\r\n def path(self) -\u003e str:\r\n return \"/test\"\r\n\r\n @property\r\n def path_pattern(self) -\u003e str:\r\n return \"/test\"\r\n\r\n @property\r\n def method(self) -\u003e str:\r\n return \"get\"\r\n\r\n @property\r\n def body(self) -\u003e t.Optional[t.Union[bytes, str, t.Dict]]:\r\n return None\r\n\r\n @property\r\n def content_type(self) -\u003e str:\r\n return \"\"\r\n\r\n @property\r\n def mimetype(self) -\u003e str:\r\n return \"\"\r\n\r\n\r\nclass OpenAPIResponse:\r\n def __init__(self, data: any) -\u003e None:\r\n self._data = data\r\n\r\n @property\r\n def data(self) -\u003e t.Optional[bytes]:\r\n return self._data\r\n\r\n @property\r\n def status_code(self) -\u003e int:\r\n return 200\r\n\r\n @property\r\n def content_type(self) -\u003e str:\r\n return \"application/pdf\"\r\n\r\n @property\r\n def mimetype(self) -\u003e str:\r\n return \"application/pdf\"\r\n\r\n @property\r\n def headers(self) -\u003e t.Mapping[str, t.Any]:\r\n return {\r\n \"Content-Type\": \"application/pdf\",\r\n \"Content-Disposition\": \"attachment; filename=invoice.pdf\",\r\n }\r\n\r\n\r\nif __name__ == \"__main__\":\r\n with open('example-pdf.pdf', 'rb') as f:\r\n pdf_content = f.read()\r\n\r\n open_api_spec = OpenAPI.from_dict({\r\n \"openapi\": \"3.1.0\",\r\n \"info\": {\r\n \"title\": \"Test spec\",\r\n \"version\": \"1.0.0\",\r\n \"description\": \"Test spec\",\r\n },\r\n \"servers\": [\r\n {\"url\": \"https://example.com\"},\r\n ],\r\n \"paths\": {\r\n \"/test\": {\r\n \"get\": {\r\n \"responses\": {\r\n \"200\": {\r\n \"description\": \"OK\",\r\n \"content\": {\r\n \"application/pdf\": {\r\n \"schema\": {\r\n \"type\": \"string\",\r\n \"format\": \"binary\",\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n }\r\n }\r\n })\r\n\r\n request = OpenAPIRequest()\r\n response = OpenAPIResponse(data=pdf_content)\r\n open_api_spec.validate_response(request=request, response=response)\r\n```\r\n\r\n### OpenAPI Core Version\r\n\r\n0.19.1\r\n\r\n### OpenAPI Core Integration\r\n\r\nNatively using openapi-core\r\n\r\n### Affected Area(s)\r\n\r\nValidation\r\n\r\n### References\r\n\r\n_No response_\r\n\r\n### Anything else we need to know?\r\n\r\n_No response_\r\n\r\n### Would you like to implement a fix?\r\n\r\nNone","author":{"url":"https://github.com/its-hammer-time","@type":"Person","name":"its-hammer-time"},"datePublished":"2024-06-13T22:00:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/245/openapi-schema-validator/issues/245"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ef1b981f-3714-af8c-86b2-3494f939fa09 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C022:3E913B:19F6CF5:24118D1:69778449 |
| html-safe-nonce | 32f5ac204f1ac3b96b0721380d7b19914cec8a9078fe8f658fc6bd103dd23b63 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDIyOjNFOTEzQjoxOUY2Q0Y1OjI0MTE4RDE6Njk3Nzg0NDkiLCJ2aXNpdG9yX2lkIjoiNzgwMjcxMTEzNzU5NzIyODEwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 135dc5df2f5a8c1944f796f950ca96c66e7845045401f00eddd14c077a60b6ce |
| hovercard-subject-tag | issue:3748016845 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openapi/openapi-schema-validator/245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c25b4894d6e60e5cf1d237a84357174597dcb5d3d7aabdd329e2d735628e65d/python-openapi/openapi-schema-validator/issues/245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c25b4894d6e60e5cf1d237a84357174597dcb5d3d7aabdd329e2d735628e65d/python-openapi/openapi-schema-validator/issues/245 |
| og:image:alt | Actual Behavior I hacked together the code below so that I could test this library in isolation, but for context we are using it inside of a Pyramid app. When I run the case below, I get the follow... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | its-hammer-time |
| hostname | github.com |
| expected-hostname | github.com |
| None | fd37f8e74ecc49b700617ea694fa6d7b395b6c9a4b79c59b3014da220462ac69 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openapi/openapi-schema-validator git https://github.com/python-openapi/openapi-schema-validator.git |
| octolytics-dimension-user_id | 126442889 |
| octolytics-dimension-user_login | python-openapi |
| octolytics-dimension-repository_id | 245119225 |
| octolytics-dimension-repository_nwo | python-openapi/openapi-schema-validator |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 245119225 |
| octolytics-dimension-repository_network_root_nwo | python-openapi/openapi-schema-validator |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 523f6485bbeeb9958ec03260b225e9183734585d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width