Skip to content
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

Proposal: v3.1.X add file and binary types to support bytes/file only use cases #3024

Closed
spacether opened this issue Sep 7, 2022 · 0 comments

Comments

@spacether
Copy link

spacether commented Sep 7, 2022

There is a need to send and receive bytes and files via endpoints.
Typically one does this using

  • content-type: application/octet-stream and sends or receives bytes (file name info is not needed) per rfc 2046
  • content-type: multipart/form-data where one sends multiple files (and file name info is needed) per rfc 7578

Json schemas do not have data types that include these types of binary information
The v3.1.0 spec says that we should describe these schemas with empty schema which should allow everything.
But that implies that there are allowed types outside of the json schema ecosystem which we need here.

I propose adding two new types which would be used in openapi contexts:

  • binary
  • file

Which are used by the above use cases and only allow in content of those kinds.
binary is python type bytes
file is python file like object which must include a file name
Ways one could do this:

  1. One could do this with a new keyword:
opeanpi-type: binary
opeanpi-type: file

or allow in both types

opeanpi-type: 
- binary
- file

And that keyword must only apply where a schemas type is unset
2. Allow binary and file as additional types that are valid values for the json schema type keyword
3. Allow describing these types as not json schema types (but this does still not allow differentiation between file and binary types)

not:
  type:
    - object
    - list
    - string
    - number
    - integer
    - "null"
    - boolean  
  1. Allow describing these types as no type (I don't like this, it is too vague)
type: []

This matters for code generation because when describing the types of data that a schema can store, one needs to include all types. Per the openapi definition, binary data is also accepted into empty schema. So when one is sending binary data via
application/octet-stream or multipart/form-data the allowed types would be:

  • all json schema types + binary

though application/octet-stream would only allow binary data in.

Or tooling needs to take empty schema into consideration for certain content types only and say in this case empty schema means binary only.
It is better to be explicit and have a way of saying this can take binary data only and not this empty schema means binary only, or it allows in all json types and binary even though only binary is used here.

Openapi 3.1.0 spec guidance:

One should be using contentMediaType + contentEncoding
But that assumes that binary data can be converted to a string representation for local storage as a string.
Maybe the code does not know the encoding of the binary data. If that is the case, then we cannot convert those bytes into a string representation. Also, when we do that with files, we lose the filename information.
That filename info is needed for multipart/form-data transmission of files.

@spacether spacether changed the title Proposal: v3.1.X add file and binary types to support bytes and file use cases Proposal: v3.1.X add file and binary types to support bytes/file only use cases Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant