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

OAS 3.1 file upload description is invalid #567

Closed
yvoitenko opened this issue Oct 8, 2024 · 2 comments · Fixed by #569
Closed

OAS 3.1 file upload description is invalid #567

yvoitenko opened this issue Oct 8, 2024 · 2 comments · Fixed by #569

Comments

@yvoitenko
Copy link
Contributor

According to OAS 3.1 specification, the format keyword is omitted for file uploads, and the contentEncoding and contentMediaType keywords are used instead.

In contrast with the 3.0 specification, the format keyword has no effect on the content-encoding of the schema. JSON Schema offers a contentEncoding keyword, which may be used to specify the Content-Encoding for the schema. The contentEncoding keyword supports all encodings defined in RFC4648, including "base64" and "base64url", as well as "quoted-printable" from RFC2045. The encoding specified by the contentEncoding keyword is independent of an encoding specified by the Content-Type header in the request or response or metadata of a multipart body -- when both are present, the encoding specified in the contentEncoding is applied first and then the encoding specified in the Content-Type header.

This affects the "Try request" functionality in different UI clients. For example, "Swagger UI" seems to have backwards compatibility, and allows file upload anyway, while "Stoplight Elements" doesn't.

So, currently it generates this from the file validation rule:

media:
  type: string
  format: binary
  description: 'A file intended for a document.'

But if we specify the OAS 3.1 dialect for generation, we should get something like this:

media:
  type: string
  contentMediaType: 'application/octet-stream'
  description: 'A file intended for a document.'

I created a workaround for this in my fork package, works well in both "Swagger UI" and "Stoplight Elements", for both OAS 3.0 and 3.1. Please, feel free to discover it in this PR.

Thanks!

@romalytvynenko
Copy link
Member

@yvoitenko nice! Can you please submit a PR to this repo?

@yvoitenko
Copy link
Contributor Author

@romalytvynenko no problem, here it is!

#569

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

Successfully merging a pull request may close this issue.

2 participants