-
Notifications
You must be signed in to change notification settings - Fork 2.2k
@ApiParam of type InputStream needs special handling #1531
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
What are your dependencies? If you're not using the swagger-jersey-jaxrs module, I'd expect to see this behavior, which is indeed not helpful. But in the module, you'll see that a |
@fehguy Thanks for the quick reply. We're using swagger-jersey2-jaxrs 1.5.4. I don't believe the
|
OK got it. That's different then--and you're bringing up a different use case than the The You can always send BASE64-encoded strings to the server by sending a JSON body with a content structure like such: {
"contents": "VGhpcyBpcyBhbiBhbWF6aW5nIGZpbGUgY29udGVudCB0aGF0IHJlYWxseSByZWFsbHkgaXMgYXdlc29tZS4="
} This would still be |
@fehguy We understand it's different, but it's also the way every major REST API that takes file uploads works. That includes S3, OpenStack, Box, DropBox, etc. all of which take the file as the raw body of the request either through a PUT or POST. So it's in no way a fringe use case. It's the most efficient way to get a file local from the client (which in many cases will not be a browser) up to a server because no encoding is required, and it's directly supported by most HTTP client libraries. We understand Swagger UI upload support might be an issue because the browser may not allow that type of direct upload of a file selected by the user (we haven't tried this), but at least Swagger UI can document it correctly. |
Sure, that's fair, but if you're looking for support, help with more details. Specifically:
|
No problem. The details are this. The scenario is a binary file (think Word document, or PDF) sent as the body of the HTTP POST request with Content-Type = application/octet-stream and no encoding (in which case the client code will set Content-Length) or a Transfer-Encoding negotiated between the client code and the server (like chunked, ZIP, etc.). No JSON, no base64, etc. In this case, the InputStream on the server (i.e. in the I refer you to the W3C HTTP spec where an Entity Body is defined as I think maybe we're not quite on the same page. Am I missing something here? |
@fehguy - I believe @BigSocial is looking for the solution as described at OAI/OpenAPI-Specification#50 (comment). |
I have a similar problem with @ApiParam and InputStream. My endPoints look very much like the ones above - only difference is that my InputStream is not a file. I use Jackson (from fasterxml) to transform (map) the InputStream into an Object (in the following example it maps into a Comparison.class). Here is an example:
This produces the same Swagger documentation as listed in the exmaple provided by @BigSocial - the body parameter is treated like an InputStream (which of course it is)... For documentation purposes I would like to be able to define what the InputStream actually is (in my case a Comparison.class) Since we are using an old version of JBoss (which still uses the codehaus version of Jackson) the mapping cannot be done prior to the endPoint call - because the codehaus mapping is done wrong.
Notice - InputStream has been replaced with Comparison What I would like is a "datatype" parameter on the @ApiParam: @ApiParam(value="...", datatype="Comparison.class", ...) In this way the documentation produced by Swagger would be more correct. The "datatype" parameter would always superseed the actual Parameter class |
I have a very similar need where I need to both upload and download files in my API and the files are encrypted/decrypted therefore I cannot send Java File objects, I need to work with InputStream. Further, I'm trying to generate the client code and server skeleton from the swagger definition of the API. I think the spec needs a way to describe a binary object that shouldn't be handled in memory. In java the corresponding type would be java.io.InputStream. I propose this: Data Types
|
Not sure the spec should deal with how things are handled but rather what they are. To me, in your case, |
What about multiple representations using |
I have a situation similar to that of @HenrikHL . I am accepting a relatively large blob of JSON containing an array of entities. I want to be able to accept the request body as an |
I too have the same problem as @HenrikHL and @HaloFour . I was looking for the same solution as @HenrikHL as well. he ability to override the datatype via @ApiParam.dataType=Foo.class It would also help solve some problems we have where the resource method needs to consume a concrete class, whereas the actual Resource is best described by an interface. I recognize that this is not the same use case as the original one, so would we be better off creating a separate issue for this use case ? |
I believe @webron has covered the current spec behavior in his comments. For 3.0, that will change. |
This Java/Jersey code...
...works perfectly (i.e. it allows access to the unencoded body) but currently generates this Swagger 2.0...
The result is Swagger UI generates the unhelpful...
...and swagger-codegen generates a Java client that treats InputStream as if it were part of my model (i.e. creates a io.swagger.client.model.InputStream class), not an important concept in Java/Jersey.
Is there any way right now to make Swagger (core, UI, codegen, etc.) understand that an InputStream param should be treated as a "raw" file upload? If not, consider this a issue.
Also see my original comment on Sep 27 2015 here OAI/OpenAPI-Specification#326
The text was updated successfully, but these errors were encountered: