-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Clarify 'byte' format #50
Comments
@fehguy - just making sure, is that correct? 'byte' is a binary value encoded in base64? |
Yes I believe so. I'm not positive that there can't be different encoding based on media type though. Might keep this open for further clarification |
@fehguy @webron recently a user reported using In view of the conversation above, I wonder if you can confirm again |
@wing328 - do you remember if the user used it for input, output or both? |
@webron both as mentioned in swagger-api/swagger-codegen#733 |
@wing328 - FWIW, I think the proper way to document it with Swagger 2.0 would be to set the type to |
I would like to propose a way to resolve this and support both raw binary and base64 encoded input and output, depending on the content type. Please see the detailed proposal bellow. Swagger Spec Update Proposal – Handling of Binary Input and OutputGoals
ScopeThis proposal deals only with binary data passed to the server as a byte array in a POST or PUT request body or returned to the client as the response body of a request. It does not cover the topic of file uploads and downloads. From the specification language point of view, this proposal only affects operations whose body parameter and/or the response is of type "string" and format "byte" For example:
PrincipleThe expected data format to be passed in the cases mentioned above is determined by the content type specified in the "consumes" / "produces" properties of the operation. Spec DetailsWhen the body parameter is of type "string" and format "byte", there are two cases depending on the value of the "consumes" property of the operation:
the input data passed by the parameter to the server is expected to be “raw” binary data (not encoded).
The expected response body is “raw” binary data Code Generation (Java as a non-normative example)The wrapper method generated by swagger-codegen should have a byte[] input parameter in any case of a "type": "string", "format": "byte" body parameter. The method's code should call base64encode in order to convert the data in case an encoded string is expected by the server (i.e. the consumed content type is not "application/octet-stream"). No conversion should happen in case binary data is expected (i.e. the consumed content type is "application/octet-stream"). Similarly, the wrapper method should have a byte[] return value in any case of a "type": "string", "format": "byte" response. The method's code should call base64decode in order to convert the data in case an encoded string is expected from the server (i.e. the produced content type is not "application/octet-stream"). No conversion should happen in case binary data is expected (i.e. the produced content type is "application/octet-stream"). |
@boazsapir - thanks for the elaborate proposal. We're trying to gather some more information here. The original intent was that What would really help us is if you can find us official resources describing sending binary data using |
@webron please refer to this official documentation: http://www.iana.org/assignments/media-types/application/octet-stream |
shouldn't base64 encoding be an artifact of the thing that consumes the particular format. For example if my endpoint does: consumes:
- application/x-protobuf
- application/json There are essentially 2 types of formats that we send binary and text based. For a text based format like json or xml when you specify an array of bytes it has to resort to base64 encoding to make it fit in the wire format. With application/octet-stream you're also saying you want a binary format so the same rule applies. |
@casualjim do you agree that in the case of application/octet-stream the automatically generated code (in swagger-codegen) should always send/receive a byte array without encoding? |
@boazsapir - we can't really change the spec. The combination of |
Okay, I've searched a bit around the JSON Schema world and came across a reference to the JSON Schema Hypermedia which we don't really support (for now) but has a possible related solution via the If you look here and follow the
The first catch is that we are not in a position to change the structure of the current spec. For this, I would say let's stick to The second catch is the meaning of 'byte' as a 'format'. Since the original intent was I find this could be a good start for better defining file transfers in the next version of the spec, and believe it should satisfy the current needs of the people involved. @boazsapir, @fehguy, @wing328 - would love to hear your opinions, and please try to find faults with it so we can fix those if they exist prior to moving forward with the tooling support. |
@webron this seems to solve my issue of supporting raw binary data, and is even simpler than my proposed spec change as it does not involve differentiation by content type (consumes/produces). |
I don't think we should impose it in this version of the spec as we're just adding clarifications and not adding restrictions. The way it would be interpreted is tool-dependent and we can say that combinations of |
ok, so from my perspective your proposal is good |
I can provide an implementation by modifying the pull requests I submitted on Sunday |
@boazsapir - I'd like to get @fehguy's feedback before we finalize it, as someone who knows the spec well, to make sure we didn't miss any obvious problems. We also need to make sure this gets cross-tool support. |
@webron your proposed change looks good me. Thanks! |
@webron @boazsapir sorry for the lag on this. I think the proposal from @webron is good |
Thanks everyone for the feedback. The spec has been modified to reflect the clarifications in this issue. I'll close this issue as it related to the |
Basically, should be a binary value encoded in base64.
The text was updated successfully, but these errors were encountered: