-
-
Notifications
You must be signed in to change notification settings - Fork 482
openapi3filter: use FileBodyDecoder if the format is specified as binary #1088
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
Conversation
|
I am a bit confused about the failing tests, P.S: Looks like my test is creating some side-effects on the other tests as removing it fixes the problem but running it standalone works fine... P.S2: It turns out the existing upload zip test was polluting the environment and needed a cleanup |
|
Thanks! Also, I love nhost :) |
|
@fenollp @dbarrosop it is a field of multipart form, when the attachment sent has a header of type registered in init, it will try to decode it with registered decoder, while i expect FileBodyDecoder on binary fields maybe we could do something like |
|
Hello, openapi: 3.0.3
info:
title: File Upload API
version: 1.0.0
paths:
/upload:
post:
summary: Upload a file
description: Use always FileBodyDecoder
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
description: The file to upload
description:
type: string
description: File description (optional)
required:
- file
encoding:
file:
contentType: application/octet-stream
...
/upload/known-types:
post:
summary: Upload known file types
description: Use more specific decoders
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
yamlFile:
type: string
format: binary
description: YAML file only - server validates content type and format
metadata:
type: object
properties:
name:
type: string
version:
type: string
required:
- yamlFile
encoding:
yamlFile:
contentType:
- application/yaml
- text/yaml
- application/x-yaml
# This restricts what content types are acceptable
...This is a big breaking change though so it might be tricky to implement |
|
thanks for getting back, i agree that being able to add multiple content types as a list in the encoding object would be convenient, but as you said, its a breaking change i think it might make life a bit easier if we support FileBodyDecoder by default on binary field, and as before, you will be able to specify content-type in the encoding object, that encoding content type will be used for contentType validation could you look into the code? |
This allows uploading arbitrary files treating them as binary by specifying a schema like:
without having to add
openapi3filter.RegisterBodyDecoder("some/thing", openapi3filter.FileBodyDecoder)for every particular type of file that users might be uploading and for which we may have no knowledge of ahead of time when building a service to upload arbitrary files.I don't think this is currently supported in any other way, I don't think so.