Missing auth from OpenAPI Schema #7929
Unanswered
jerinpetergeorge
asked this question in
Question & Answer
Replies: 3 comments 3 replies
-
I'm not sure whether this functionality is available in the native DRF doc or not. I hope you guys can be more certain in this @tomchristie @carltongibson (sorry for the noise :) ) |
Beta Was this translation helpful? Give feedback.
2 replies
-
See #7516 |
Beta Was this translation helpful? Give feedback.
1 reply
-
Until something gets rolled in here's a hard-coded solution I used in my case where my API uses JWT token authentication. I created a custom renderer based off of the from rest_framework.compat import yaml
from rest_framework.renderers import BaseRenderer
class OpenAPIWithJWTBearerSecuritySchemeRenderer(BaseRenderer):
media_type = 'application/vnd.oai.openapi'
charset = None
format = 'openapi'
def __init__(self):
assert yaml, 'Using OpenAPIRenderer, but `pyyaml` is not installed.'
def render(self, data, media_type=None, renderer_context=None):
# disable yaml advanced feature 'alias' for clean, portable, and readable output
class Dumper(yaml.Dumper):
def ignore_aliases(self, data):
return True
data["security"] = [{"bearerAuth": []}]
assert "components" in data
data["components"]["securitySchemes"] = {"bearerAuth": {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"}}
return yaml.dump(data, default_flow_style=False, sort_keys=False, Dumper=Dumper).encode('utf-8') |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have set up swagger doc using our documentation (Schema-(Doc) and Documenting your API-(Doc)) and I've got the result as below

Looks good!!!
But, the generated UI doesn't have any security options(as per the Open API schema). Did I miss something here? 🤔
Ideally, looking for this Authorize button 👇 👇

Beta Was this translation helpful? Give feedback.
All reactions