-
-
Notifications
You must be signed in to change notification settings - Fork 541
Stream is not a File type [NSwag] #445
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
Comments
The type file is nit valid in json schema - it is only allowed in swagger. How is a stream property serialized in json.net? Is it a byte array encoded as base64 (same as byte[])? |
I don't know how it's serialized. I hope I'm clear enough :) |
Yes. Is a stream body parameter encoded as formData? Same as HttpPostedFile? |
In my case it's a raw binary content without formData nor multipart. And I assume it always be the case. Otherwise you could use IFormFile or HttpPostedFile type from aspnet. |
I think we have to add this special case here: The question is: How is this correctly described in a Swagger spec? As seen in swagger-api/swagger-codegen#669
But this will not expect a binary body but a JSON string which is base64 encoded like "ABC=" Maybe we just use body and type file:
and handle this correctly in the code generators...? |
Or maybe its better to use
and consumes "application/octet-stream" as described in OAI/OpenAPI-Specification#50
|
There is a lot of change for that in the 3.0 spec but for the 2.0:
So I assume body and type file is not correct. Indeed type: string and format: byte should be a better idea. But in that case it should be mapped to a Stream (that support byte[] and it allow streaming of request which is interesting in the case of big file) |
Or even better "schema": {
"type": "string",
"format": "binary"
} Per swagger 2.0 spec
and keeping "consumes": [
"application/octet-stream"
] |
"binary" is not an official format string in JSON Schema, I think we should go with "byte" and "application/octet-stream" |
byte is supposed to be "base64 encoded characters". |
I see it like that: If "consumes" is "application/json" it is "base64 encoded characters" don't you think this is how it works? |
Ok I have this operation:
but this gives me the following exception:
How is this working? |
This is the client
|
I created a custom InputFormatter (https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-formatters#how-to-create-a-custom-formatter-class) to bind Stream type. |
Can you please provide a simple handler (ideally applicable with a single attribute) so that we can add it to the ASP.NET (Core) package and add documentation for this feature? |
What do you mean by an handler? |
A custom formatter which can be applied to an operation method with an attribute |
The only way to add a inputformatter is by adding it in the startup class on the MvcOptions object. I will take a look for ModelBinding if we could do it there. |
Is there any reason why Stream type fro System.IO is not considered as a File type in json?
If no I could make a PR to resolve this.
Thanks
The text was updated successfully, but these errors were encountered: