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

Support creating file schema for file response #447

Closed
greyli opened this issue Jul 3, 2023 · 0 comments · Fixed by #448
Closed

Support creating file schema for file response #447

greyli opened this issue Jul 3, 2023 · 0 comments · Fixed by #448
Assignees
Labels
Milestone

Comments

@greyli
Copy link
Member

greyli commented Jul 3, 2023

We support creating file fields via the apiflask.schemas.File field class, and use the metadata to set the type and the format:

class ImageIn(Schema):
    image = File()

But we still need to support creating the schema for file response. In that case, the whole response is a file, there isn't a key for the file. For example:

paths:
  /report:
    get:
      summary: Returns the report in the PDF format
      responses:
        '200':
          description: A PDF file
          content:
            application/pdf:
              schema:
                type: string
                format: binary

I will create a FileSchema class that accepts type and format as arguments, then create the file schema from it. Example usage:

from apiflask.schemas import FileSchema

@app.get('/files/<filename>')
@app.output(FileSchema(type='string', format='binary'), content_type='image/png', description='An image file')
def get_file(filename):
    return ...
@greyli greyli added the feature label Jul 3, 2023
@greyli greyli added this to the 2.0.0 milestone Jul 3, 2023
@greyli greyli added this to To do in APIFlask 2.0 via automation Jul 3, 2023
@greyli greyli self-assigned this Jul 3, 2023
@greyli greyli moved this from To do to In progress in APIFlask 2.0 Jul 4, 2023
APIFlask 2.0 automation moved this from In progress to Done Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant