Skip to content

Issue#26 : New Feature - Option to add custom tag to group Endpoints #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions flask_swagger_generator/generators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ def wrapper(*args, **kwargs):
return wrapper
return swagger_security

def path_tag(self, tag):
def swagger_path_tag(func):

if not self.generated:
self.specifier.add_path_tag(
func.__name__, tag
)

@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper
return swagger_path_tag

def create_schema(self, reference_name, properties):
return self.specifier.create_schema(reference_name, properties)

Expand All @@ -116,17 +131,16 @@ def index_endpoints(self, app):

for rule in app.url_map.iter_rules():

group = None
function_name = rule.endpoint
if len(rule.endpoint.split(".")) > 1:
group, function_name = rule.endpoint.split('.')
self.specifier.add_endpoint(
for path_tag in self.specifier.path_tags:
if path_tag.get("function_name") == function_name:
group = path_tag.get("tag")
self.specifier.add_endpoint(
function_name=function_name,
path=str(rule),
request_types=rule.methods,
group=group
)
else:
self.specifier.add_endpoint(
function_name=rule.endpoint,
path=str(rule),
request_types=rule.methods,
)
4 changes: 4 additions & 0 deletions flask_swagger_generator/specifiers/swagger_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def add_request_body(self, function_name, schema):
def add_security(self, function_name, security_type: SecurityType):
raise NotImplementedError()

@abstractmethod
def add_path_tag(self, function_name, tag):
raise NotImplementedError()

def set_application_name(self, application_name):
self.application_name = application_name

Expand Down
5 changes: 5 additions & 0 deletions flask_swagger_generator/specifiers/swagger_three_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def __init__(self):
self.schemas = []
self.responses = []
self.securities = []
self.path_tags = []

def perform_write(self, file):
# Add all request bodies to request_types with same function name
Expand Down Expand Up @@ -675,6 +676,10 @@ def add_security(self, function_name, security_type: SecurityType):
security_model = SwaggerSecurity([function_name], security_type)
self.securities.append(security_model)

def add_path_tag(self, function_name: str, tag):
path_tag = {"function_name": function_name, "tag": tag}
self.path_tags.append(path_tag)

def create_schema(self, reference_name, properties):
schema = SwaggerSchema(reference_name, properties)
self.schemas.append(schema)
Expand Down