Closed amitabduls15 closed 2 years ago
same problem,but in HTTPMethodView way.
class Source(HTTPMethodView):
@doc.summary("监听指定channelid的计时器")
@doc.tag("event")
# @doc.consumes(doc.String(name="channelid", description="channel的唯一id.", required=True), location="uri")
@doc.produces(doc.String(description="sse消息"), description="监听流", content_type="text/event-stream;charset=UTF-8")
async def get(self, request: Request, channelid: str) -> HTTPResponse:
ok = await redis.sismember("timer::channels", channelid)
log.info('redis.sismember("timer::channels", channelid) result', result=ok)
if not ok:
return json({"msg": "未找到channel"}, status=404, ensure_ascii=False)
p = redis.pubsub()
await p.subscribe(f"timer::{channelid}")
response = await request.respond(
content_type="text/event-stream;charset=UTF-8",
headers={
"Connection": "keep-alive",
"Transfer-Encoding": "chunked",
"Cache-Control": "no-cache"
}
)
p = redis.pubsub()
await p.subscribe('timer::golbal')
log.info("subscribe ok")
while True:
message = await p.get_message(ignore_subscribe_messages=True, timeout=0.01)
if message is not None:
log.info("get msg", msg=message)
sse = SSE.from_content(message["data"])
if sse.event == "EOF":
await response.send(SSE(comment="EOF").render(), True)
break
else:
await response.send(message["data"])
return response
timernamespace.add_route(Source.as_view(), "/<channelid:string>", strict_slashes=True)
Same here, i cant edit path variables.
@ahopkins is there something we need to add in the @doc decorator so that the path variable should be edited on browser? I didnt find any info about this on the project readthedocs.
Hi you can use the "path" value in the location param:
@app.get("/trends/<woeid:int>")
@doc.consumes(doc.Integer(name="woeid"), location="path")
I hope this help.
@doc.consumes(doc.Integer(name="woeid"), location="path")
Hi you can use the "path" value in the location param:
@app.get("/trends/<woeid:int>") @doc.consumes(doc.Integer(name="woeid"), location="path")
I hope this help.
Worked. Thanks
It appears that adding the parameter to @doc.consumes(...)
with location
can solve this issue as @nuxion mentioned above.
@amitabduls15, do you still have any problem with it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.
I can't enter a path variable on my endpoint in swagger, but when using curl it does. code:
Here is a screenshot of my swagger:
In the screenshot above the path variable I mean is level.
Environment
I don't know if it's an error in my code or it's a bug, but in sanic-openapi version 0.6.* this code is what I usually use and it works.
thanks