GithubHelp home page GithubHelp logo

Comments (7)

nuxion avatar nuxion commented on June 4, 2024 3

Hi you can use the "path" value in the location param:

@app.get("/trends/<woeid:int>")
@doc.consumes(doc.Integer(name="woeid"), location="path")

path_example

I hope this help.

from sanic-openapi.

hsz1273327 avatar hsz1273327 commented on June 4, 2024

same problem,but in HTTPMethodView way.

image

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)

from sanic-openapi.

Cayke avatar Cayke commented on June 4, 2024

Same here, i cant edit path variables.

Captura de Tela 2021-08-25 às 18 04 55

from sanic-openapi.

Cayke avatar Cayke commented on June 4, 2024

@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.

from sanic-openapi.

Cayke avatar Cayke commented on June 4, 2024

@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")

path_example

I hope this help.

Worked. Thanks

from sanic-openapi.

ChihweiLHBird avatar ChihweiLHBird commented on June 4, 2024

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?

from sanic-openapi.

stale avatar stale commented on June 4, 2024

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.

from sanic-openapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.