Comments (8)
Yup, that makes sense. That is a feature we need to add still: https://github.com/sanic-org/sanic-ext/blob/main/sanic_ext/extensions/openapi/openapi.py#L230
Hopefully we can squeeze this one into the upcoming release.
from sanic-ext.
from sanic-ext.
Odd. I am curious to know if it is that we are generating invalid OAS, or is an issue with the client. Do you know that this works in other Swagger installations?
from sanic-ext.
I don't think this is related, but there is an open PR re: that decorator: #21
from sanic-ext.
I found the problem and it is specifically related with the Authorization header.
The thing is in this case, as mentioned here
"Note: Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords"
So for the Authorization header i think the sanic-ext needs to implement the specification described here.
So the ir no problem with the openapi.parameter for others headers except headers mentioned above.
In the case of Authorization, we need to generate something like this:
{"openapi": "3.0.0",
"info": {
"title": "API",
"version": "1.0.0",
"contact": {
}
},
"components":
{ "securitySchemes":{
"BearerAuth":{
"type": "http",
"scheme": "bearer"
}
}
},
"paths": {
"/": {
"get": {
"operationId": "get_route_name",
"summary": "Hello World",
"security": [{"BearerAuth":[]}],
"responses": {
"default": {
"description": "OK"
}
}
}
}
},
"tags": [
],
"servers": [
]
}
from sanic-ext.
Thanks, in the mean time if someone get stuck with this and found this thread, you could do a ugly hack like this:
# You must add security schemas to the singleton Builder of the specification..
app = Sanic("app", log_config=define_logging_config(LOGGING_CONFIG))
....
# Modify Singleton builder to add security schemes, ex: add a bearerAuth schema for bearer tokens :
SpecificationBuilder().add_component(
"securitySchemes", "BearerAuth", {"type": "http", "scheme": "bearer"}
...
Extend(app)
from sanic_ext import openapi
# This hack is to override default behavior of sanic_ext openapi allow **secured** decorator.
def secured(*args, **kwargs):
# raise NotImplementedError(
# "SecuritySchemas are not yet implemented in sanic-openapi 0.6.3, "
# "hopefully they should be ready for the next release."
# )
def inner(func):
OperationStore()[func].secured(*args, **kwargs)
return func
return inner
openapi.secured = secured
# Finally annotate your secure route with:
@blueprint.route("/some_route", methods=["POST"])
@openapi.secured("BearerAuth")
Tested on sanic and sanic_ext 21.9.3
from sanic-ext.
Working on this
from sanic-ext.
This is now released in v21.12.2 without @dacasals nice hack.
from sanic-ext.
Related Issues (20)
- [Question] OpenAPI spec available on all subdomains, and route exclusion without decorators does not seem to work.
- [Bug] Dependeny Injection throw exceptions by default if @classmethod constructors don't return value/objects
- [Feature Request]
- [Bug] OpenAPI definition does not include placeholder for "headers"
- [Bug] Json validator throws 500 instead of 400
- [Feature Request] Response Compression
- [Bug] Can't use `pydantic>=2.0` model in OpenAPI definition HOT 1
- [Bug] Can't document/exclude websocket routes with OpenAPI decorator
- [Bug] Subheader "parameter" missing in sanic extensions document
- [Bug] Can't apply openapi decorators to blueprintss' routes
- [Bug]TypeError: listener() got an unexpected keyword argument 'priority' HOT 1
- [Bug] Documentation: dead link to the setting
- Query params validation is completely broken HOT 2
- Question regarding licensing info
- [Bug] Doubly defined objects in the output specification #260 HOT 2
- [Bug] The tags in OpenAPI yaml are not effective
- [Bug] Pydantic query validation with extra data not defined in model raise's KeyError HOT 2
- add project to nix packages
- Add support for scalar.com OpenAPI documentation
- [Bug] Sanic validation extension failed to validate aliased pydantic model field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic-ext.