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

Swagger UI not allowing upload of text files. #528

Open
k1rm4d4 opened this issue Jul 10, 2023 · 4 comments
Open

Swagger UI not allowing upload of text files. #528

k1rm4d4 opened this issue Jul 10, 2023 · 4 comments

Comments

@k1rm4d4
Copy link

k1rm4d4 commented Jul 10, 2023

Hello!

I was trying to upload two .txt files to do some text processing. I uploaded through the input fields in Swagger UI generated by API. But, the Swagger-UI gives me the following error:

Details

image

Here's the relevant parts of the code:

class HeaderSchema(ma.Schema):
    id = ma.fields.String()

class MultiFileSchema(ma.Schema):
    prev_file = Upload(format='binary')
    post_file = Upload(format='binary')
    

class FormSchema(ma.Schema):
    type = ma.fields.String()

@blp.route("/result-file")
class ResultFile(MethodView):
    @blp.arguments(HeaderSchema, location='headers')
    @blp.arguments(MultiFileSchema, location='files')
    @blp.arguments(FormSchema, location='form')
    @blp.response(200)
    def post(self, header_args = None, files_data = None, form_data = None ):
        .
        .
        .

The code works fine when tested using Postman. Problem only shows up in Swagger-UI

Also, when I didn't attach the files in the Swagger-ui, the code worked fine and returned intended response, so likely the issue might be with the Upload() field.

What could I be doing wrong?

Thanks!

@lafrech
Copy link
Member

lafrech commented Jul 10, 2023

Maybe the Upload field doesn't yield the proper documentation.

I'm open to suggestion about how to improve/fix this if it is the case.

It might be interesting to also try with different OpenAPI versions, and perhaps with RapiDoc.

@k1rm4d4
Copy link
Author

k1rm4d4 commented Jul 11, 2023

Hello, so I tried setting the OPENAPI_VERSION = "2.0", and it worked!
Now, I'm able to upload the files successfully. But, I have no idea why using OpenAPI 2x made it work.

I will try to peek into the source files later to check if I can find the cause.

@lafrech
Copy link
Member

lafrech commented Jul 11, 2023

OpenAPI 2 is quite different and although I never heard of a deprecation date, I'd be reluctant to push for its use.

However, there are slight differences in v3.0.x and v3.1.x and it could be worth trying both, if only to help debugging this. I don't think apispec is perfectly 3.1 compliant.

The test with RapiDoc could help ruling out a Swagger UI issue or at least give a hint.

@k1rm4d4
Copy link
Author

k1rm4d4 commented Jul 11, 2023

Okay, I'll investigate this, keeping in mind the points you have provided.

I'll check:

  • API with different versions of 3x OAS, and check out apispec also.
  • Cross check with RapiDoc

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

2 participants