Sanic-ext openapi Security Schemes didn't work help!

I am trying to add a on Security Schemes my docs page
offical page is below

I tryied add code below to my server.py

app.ext.openapi.add_security_scheme("api_key", "apiKey")
app.ext.openapi.secured()

but nothing happened ,it still can access http://0.0.0.0:8000/py/docs without auth

I can’t figure out why. I did as the document says

Is there something i have miss?

That is only to change the types of security your api uses in the documentation. It does not implement security in the api or the docs. It is for generating the schema only.

See OAS docs for more info.

https://swagger.io/specification/#components-security-schemes

Thanks. I got it.
So Is there any ways to add authorization on the openapi doc . I only want to these docs can be seen by developers .
I have searched the forums . But it seems no offical ways to realize it.
I also notice a discussion on Discord .Discord
It point out to write a middleware on app to match the OAS url. It works. But I still wondered is there exist other Solution?

Thanks reply again.

Middleware is probably the easiest option.

1 Like