An empty schema used to generate empty response/schema.
Version changed: 3.0.0
Removed from docs and should only be used internally. Use {} instead.
Source code in apiflask/schemas.py
515253545556575859
classEmptySchema(Schema):"""An empty schema used to generate empty response/schema. *Version changed: 3.0.0* - Removed from docs and should only be used internally. Use `{}` instead. """pass
This is used to represent a file response in OpenAPI spec. If you want to
embed a file as base64 string in the JSON body, you can use the
apiflask.fields.File field instead.
Example:
fromapiflask.schemasimportFileSchemafromflaskimportsend_from_directory@app.get('/images/<filename>')@app.output(FileSchema(type='string',format='binary'),content_type='image/png',description='An image file')@app.doc(summary="Returns the image file")defget_image(filename):returnsend_from_directory(app.config['IMAGE_FOLDER'],filename)
The output OpenAPI spec will be:
paths:/images/{filename}:get:summary:Returns the image fileresponses:'200':description:An image filecontent:image/png:schema:type:stringformat:binary
classFileSchema(Schema):"""A schema for file response. This is used to represent a file response in OpenAPI spec. If you want to embed a file as base64 string in the JSON body, you can use the `apiflask.fields.File` field instead. Example: ```python from apiflask.schemas import FileSchema from flask import send_from_directory @app.get('/images/<filename>') @app.output( FileSchema(type='string', format='binary'), content_type='image/png', description='An image file' ) @app.doc(summary="Returns the image file") def get_image(filename): return send_from_directory(app.config['IMAGE_FOLDER'], filename) ``` The output OpenAPI spec will be: ```yaml paths: /images/{filename}: get: summary: Returns the image file responses: '200': description: An image file content: image/png: schema: type: string format: binary ``` *Version Added: 2.0.0* """def__init__(self,*,type:str='string',format:str='binary')->None:""" Arguments: type: The type of the file. Defaults to `string`. format: The format of the file, one of `binary` and `base64`. Defaults to `binary`. """self.type=typeself.format=formatdef__repr__(self)->str:returnf'schema: \n type: {self.type}\n format: {self.format}'
The format of the file, one of binary and base64. Defaults to binary.
'binary'
Source code in apiflask/schemas.py
120121122123124125126127
def__init__(self,*,type:str='string',format:str='binary')->None:""" Arguments: type: The type of the file. Defaults to `string`. format: The format of the file, one of `binary` and `base64`. Defaults to `binary`. """self.type=typeself.format=format
classPaginationSchema(Schema):"""A schema for common pagination information."""page=Integer()per_page=Integer()pages=Integer()total=Integer()current=URL()next=URL()prev=URL()first=URL()last=URL()