Skip to content

Commit

Permalink
#15: Allow generator to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Jul 29, 2019
1 parent e6e418a commit 33ef610
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/swagger/swagger_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class SwaggerGenerator(object):
FILE_PATH = Path.cwd() / "swagger" / "openapi.yaml"
is_generating = False

def __init__(self):
self.endpoints = []
Expand All @@ -24,22 +25,23 @@ def resource_wrapper(self):
"""
Wrapper for Resource classes that appends the class name to the endpoints list
"""
if SwaggerGenerator.is_generating:
def decorate(cls):
self.endpoints.append(cls.__name__)
return cls

def decorate(cls):
self.endpoints.append(cls.__name__)
return cls

return decorate
return decorate

def write_swagger_spec(self):
"""
Writes the openapi.yaml file
"""
with open(SwaggerGenerator.FILE_PATH, "w+") as target:
target.write(self.get_yaml_top())
target.write(self.get_yaml_paths())
target.close()
if SwaggerGenerator.is_generating:
with open(SwaggerGenerator.FILE_PATH, "w+") as target:
target.write(self.get_yaml_top())
target.write(self.get_yaml_paths())
target.close()

@staticmethod
def get_yaml_top():
Expand Down

0 comments on commit 33ef610

Please sign in to comment.