-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for string format binary e.g. application/octet-stream #237
Comments
@mirekgw thanks for the issue. this sounds like a bug / missing feature. either way, we'll certainly add support. |
this fix should honor |
closing this out. please reopen if the issue persists |
Guys, I took latest version of lib (3.8.0) and unfortunately the issue is not fixed for me. I did some debugging and here is the result. In my case the request still fails validation. The problem is that
The issue in my case is that I think the issue is that OpenApi spec defines binary data to be represented by string for some weird reason. Because of that this part of validation needs to be handled in a special way. I would assume you should first check if the string type is @cdimascio I hope my comment makes sense. Could you please look again at the issue? |
I believe I know what the issue is. The problem is that ajv library is for JSON validation and as we all know it's text only format. OpenApi introduced strange construct i.e. string with format binary. It's not compatible with JSON so basically we can't use it (or at least we can't validate that with ajv). Not sure how to proceed here, I'm not expecting JSON spec will be extended with "binary" format for string. I suppose for me the best solution is to ignore validation of endpoints that use binary data. The question is how to achieve that with your library, as |
@mirekgw, thanks for digging in an investigating this. this is very helpful. if you don't mind sharing a canonical version of your spec and express app (perhaps via a public repo on github). I'll certainly have a look. It will help to have a reproducible example, one to explore possible workarounds/solutions |
I will prepare sample app to reproduce. As to the issue, I believe I have found an easy solution and I will create PR later today. Hopefully you will accept the idea, that is not verifying body at all if the content-type is 'application/octet-stream'. I believe verifying
|
I prepared repo with sample app that reproduces the issue, sent invite to @cdimascio. I will create PR with proposed fix in few minutes. Could you reopen the issue, as it's not fixed for me, and I don't have rights to reopen. |
Don't have rights to create branch, so I'll type here what I would put in PR.
I did this modification and all test pass exactly like without it. |
Thanks for your efforts, @mirekgw. They are greatly appreciated. I'll be sure to try your repo within the next few days. Please feel free to submit a PR. I'll definitely have a look. Thanks again! |
@mirekgw note that you create a PR even though you can't creat a branch in this repo here is how tldr Detailed steps with example: https://opensource.com/article/19/7/create-pull-request-github |
Also if u submit the PR and we merge your change to master, you will show up on this project's contributors page :) |
Created PR |
fix is in |
Hi,
Maybe I'm doing something wrong but I'm trying to have an endpoint that is used for sending binary data, with PUT. The API definition is like this:
requestBody:
description: Binary Data Stream
content:
application/octet-stream:
schema:
type: string
format: binary
It looks ok according to this: https://swagger.io/docs/specification/describing-request-body/file-upload/
When I try to execute the request, I get following error:
"message": "request.body should be string",
"errors": [
{
"path": ".body",
"message": "should be string",
"errorCode": "type.openapi.validation"
}
]
I did a quick peek at the code of your lib, and it seems you don't support binary strings. Is that correct or am I doing something wrong? If it's not implemented what is a chance you could enhance the lib with that feature?
Thanks
The text was updated successfully, but these errors were encountered: