Skip to content

Commit

Permalink
Security Schema assigner added
Browse files Browse the repository at this point in the history
  • Loading branch information
Bishwas-py committed Feb 27, 2024
1 parent bb19df1 commit 819f47c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Binary file modified djapy/core/__pycache__/auth_dec.cpython-311.pyc
Binary file not shown.
Binary file modified djapy/core/__pycache__/dec.cpython-311.pyc
Binary file not shown.
21 changes: 16 additions & 5 deletions djapy/core/openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ def set_tags(self):
self.tags = explicit_tags
self.export_tags = self.openai_info.get('tags_info', [])

def set_security(self):
self.security = self.openai_info.get('security', [])

def __init__(self, url_pattern: URLPattern, parent_url_pattern: list[URLPattern] = None):
self.export_tags = None
self.tags = None
self.security = []
self.explanation = None
self.summary = None
self.url_pattern = url_pattern
Expand All @@ -54,7 +58,9 @@ def __init__(self, url_pattern: URLPattern, parent_url_pattern: list[URLPattern]
self.request_body = {}
self.responses = {}
self.parameters = []
self.path = self.get_path_string()
self.path = None
self.set_path()
self.set_security()
self.set_docstrings()
self.set_tags()
self.set_parameters()
Expand Down Expand Up @@ -108,14 +114,14 @@ def set_parameters_from_parent_url_pattern(self):
self.parameters_keys.append(name)
self.parameters.append(parameter)

def get_path_string(self) -> str:
def set_path(self):
url_path_string = ""
for url_pattern in self.parent_url_pattern or []:
url_path_string += self.format_pattern(url_pattern)
url_path_string += self.format_pattern(self.url_pattern)
if not url_path_string.startswith('/'):
url_path_string = '/' + url_path_string
return url_path_string
self.path = url_path_string

@staticmethod
def format_pattern(url_pattern: URLPattern) -> str:
Expand Down Expand Up @@ -161,7 +167,8 @@ def dict(self):
"responses": self.responses,
"parameters": self.parameters,
"requestBody": self.request_body,
"tags": self.tags
"tags": self.tags,
"security": self.security
} for method in self.methods
}

Expand All @@ -188,6 +195,7 @@ class OpenAPI:
components = {"schemas": {}}
definitions = {}
tags = []
security = {}

def __init__(self):
self.resolved_url = get_resolver()
Expand Down Expand Up @@ -218,6 +226,7 @@ def generate_paths(self, url_patterns: list[URLPattern], parent_url_patterns=Non

def dict(self):
self.generate_paths(self.resolved_url.url_patterns)
self.components["securitySchemes"] = self.security
return {
'openapi': self.openapi,
'info': self.info.dict(),
Expand All @@ -227,10 +236,12 @@ def dict(self):
'tags': self.tags
}

def set_basic_info(self, title: str, description, version="1.0.0"):
def set_basic_info(self, title: str, description, version="1.0.0", tags_info=None, security: dict = None):
self.info.title = title
self.info.description = description
self.info.version = version
self.tags.extend(tags_info or [])
self.security = security or {}

def get_openapi(self, request):
return JsonResponse(self.dict())
Expand Down
Binary file modified djapy/core/openapi/__pycache__/__init__.cpython-311.pyc
Binary file not shown.

0 comments on commit 819f47c

Please sign in to comment.