-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseModel Config support openapi_extra
- Loading branch information
1 parent
035c127
commit f4e4b1b
Showing
8 changed files
with
216 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Author : llc | ||
# @Time : 2023/6/1 15:04 | ||
from typing import List | ||
|
||
from pydantic import BaseModel | ||
|
||
from flask_openapi3 import OpenAPI, FileStorage | ||
|
||
app = OpenAPI(__name__) | ||
|
||
|
||
class UploadFilesForm(BaseModel): | ||
file: FileStorage | ||
str_list: List[str] | ||
|
||
class Config: | ||
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 | ||
|
||
class Config: | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.