1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# -*- coding: utf-8 -*-
# @Author : llc
# @Time : 2023/6/1 15:04
from pydantic import BaseModel
from flask_openapi3 import FileStorage, OpenAPI
app = OpenAPI(__name__)
class UploadFilesForm(BaseModel):
file: FileStorage
str_list: list[str]
model_config = dict(
openapi_extra={
# "example": {"a": 123},
"examples": {
"Example 01": {
"summary": "An example",
"value": {"file": "Example-01.jpg", "str_list": ["a", "b", "c"]},
},
"Example 02": {"summary": "Another example", "value": {"str_list": ["1", "2", "3"]}},
}
}
)
class BookBody(BaseModel):
age: int
author: str
model_config = dict(
openapi_extra={
"description": "This is post RequestBody",
"example": {"age": 12, "author": "author1"},
"examples": {
"example1": {
"summary": "example summary1",
"description": "example description1",
"value": {"age": 24, "author": "author2"},
},
"example2": {
"summary": "example summary2",
"description": "example description2",
"value": {"age": 48, "author": "author3"},
},
},
}
)
@app.post("/upload/files")
def upload_files(form: UploadFilesForm):
print(form.file)
print(form.str_list)
return {"code": 0, "message": "ok"}
@app.post(
"/book",
)
def create_book(body: BookBody):
print(body)
return {"code": 0, "message": "ok"}
if __name__ == "__main__":
app.run(debug=True)
|