Comments (1)
In the following, the "something" property is added to the schema, for both classes (this is a mistake, I think).
from multiprocessing import freeze_support
import dataclasses
from sanic import Sanic, text, Request
from sanic_ext.extensions.openapi import openapi
from sanic_ext.extensions.openapi.definitions import Response, RequestBody
from sanic_ext.extensions.openapi.openapi import component
app = Sanic("app")
@component
@dataclasses.dataclass
class MyBody:
email: str
@property
def something(self) -> int:
print("Oh no you didn't!")
return "OK2"
@component
@dataclasses.dataclass
class UserProfile:
name: str
age: int
email: str
@property
def something(self) -> int:
print("Oh no you didn't!")
return "OK"
@app.route("/foo")
def foo(request):
url = app.url_for("handler", _external=True)
return text(f"URL: {url}")
@app.get("/")
@openapi.definition(
body=RequestBody({"application/json": {
"$ref": f"#/components/schemas/{MyBody.__name__}"
}}, required=True), # if body else None,
# body=RequestBody(Body, required=True),
summary="User profile update",
# tag="one",
# description=openapi.description(textwrap.dedent(func.__doc__)) if func.__doc__ else None,
response=[ # Success,
Response({
"application/json": {
"schema": {
"$ref": f"#/components/schemas/{UserProfile.__name__}"
}
}
}, status=200)
# Response(Failure, status=400)
],
)
def root(req: Request, *args, **kw): # body:UserProfile):
"""
Short description
Long Description
"""
return text("Hello")
if __name__ == '__main__':
freeze_support()
app.run(host='0.0.0.0', port=8000,
# access_log=True
)
...
# http://localhost:8000/docs/openapi.json
{"openapi":"3.0.3","info":{"title":"API","version":"1.0.0","contact":{}},"paths":{"/foo":{"get":{"operationId":"get~foo","summary":"Foo","responses":{"default":{"description":"OK"}}}},"/":{"get":{"operationId":"get~root","summary":"User profile update","description":"Long Description","responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserProfile"}}},"description":"Default Response"}},"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MyBody"}}},"required":true}}}},"tags":[],"servers":[],"security":[],"components":{"schemas":{"MyBody":{"type":"object","properties":{"something":{"type":"integer","format":"int32"},"email":{"type":"string","title":"Email"}}},"UserProfile":{"type":"object","properties":{"something":{"type":"integer","format":"int32"},"name":{"type":"string","title":"Name"},"age":{"type":"integer","format":"int32","title":"Age"},"email":{"type":"string","title":"Email"}}}}}}
from sanic-openapi.
Related Issues (20)
- pyinstaller may cause problems with sanic and/or sanic-openapi HOT 4
- can not import openapi2_blueprint from sanic_openapi HOT 2
- [UserWarning] Use instance.ctx._spec instead HOT 1
- When I run the following example, the following error occurs HOT 5
- [Feature Request][OpenApi3] Add support for enums HOT 6
- [Bug]can not render all methods with the same url when use routes of Blueprint way HOT 2
- [Bug] Decorator doc/openapi not work when using `routes of HTTPMethodView under Bluebprint instanc` way HOT 1
- [Bug] Swagger cant show path variable HOT 7
- Method POST not allowed for URL HOT 2
- Can't handle duplicate path HOT 1
- [Bug] Even after excluding an endpoint from doc, it still shows the route on swagger, although not the contents of it.
- [Feature Request] Custom Ordering of Endpoints and Authorization HOT 5
- Cannot add `allowed options`/ choices to a query parameter HOT 1
- [Feature Request] disable secure for individual route HOT 4
- distutils package is depricated in python 3.10 HOT 4
- [Feature Request] Create new Release for Sanic 21.12.0 HOT 2
- [Feature Request] Allow default endpoint in OpenAPI V3 Blueprints to be configurable HOT 1
- Duplicate route names error HOT 3
- [Bug] Doubly defined objects in the output specification
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-openapi.