-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release 0.6.2
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
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,70 @@ | ||
from flask import Flask | ||
from pydantic import BaseModel | ||
|
||
from spectree import SecurityScheme, SpecTree | ||
|
||
|
||
class Req(BaseModel): | ||
name: str | ||
|
||
|
||
security_schemes = [ | ||
SecurityScheme( | ||
name="PartnerID", | ||
data={"type": "apiKey", "name": "partner-id", "in": "header"}, | ||
), | ||
SecurityScheme( | ||
name="PartnerToken", | ||
data={"type": "apiKey", "name": "partner-access-token", "in": "header"}, | ||
), | ||
SecurityScheme( | ||
name="test_secure", | ||
data={ | ||
"type": "http", | ||
"scheme": "bearer", | ||
}, | ||
), | ||
SecurityScheme( | ||
name="auth_oauth2", | ||
data={ | ||
"type": "oauth2", | ||
"flows": { | ||
"authorizationCode": { | ||
"authorizationUrl": "https://example.com/oauth/authorize", | ||
"tokenUrl": "https://example.com/oauth/token", | ||
"scopes": { | ||
"read": "Grants read access", | ||
"write": "Grants write access", | ||
"admin": "Grants access to admin operations", | ||
}, | ||
}, | ||
}, | ||
}, | ||
), | ||
] | ||
|
||
app = Flask(__name__) | ||
api = SpecTree( | ||
"flask", | ||
security_schemes=security_schemes, | ||
SECURITY={"test_secure": []}, | ||
) | ||
|
||
|
||
@app.route("/ping", methods=["POST"]) | ||
@api.validate( | ||
json=Req, | ||
security=[{"PartnerID": [], "PartnerToken": []}, {"auth_oauth2": ["read"]}], | ||
) | ||
def ping(): | ||
return "pong" | ||
|
||
|
||
@app.route("/") | ||
def index(): | ||
return "hello" | ||
|
||
|
||
if __name__ == "__main__": | ||
api.register(app) | ||
app.run(port=8000) |
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
|
||
setup( | ||
name="spectree", | ||
version="0.6.1", | ||
version="0.6.2", | ||
author="Keming Yang", | ||
author_email="[email protected]", | ||
description=( | ||
|