Skip to content

Commit

Permalink
#50: Use pyyaml to write to file
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Sep 17, 2019
1 parent e2c2c8f commit 0f759ba
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/swagger/swagger_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ def resource_wrapper(self):
"""
Wrapper for Resource classes that appends the class name to the endpoints list
"""

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

return decorate

def write_swagger_spec(self):
Expand All @@ -253,9 +255,16 @@ def write_swagger_spec(self):
"""
if config.is_generate_swagger():
swagger_spec = SwaggerSpecification()
for endpoint in self.endpoints:
entity = Entity(endpoint)
swagger_spec.add_path(entity.entity_count_endpoint)
swagger_spec.add_path(entity.entity_id_endpoint)
swagger_spec.add_path(entity.entity_no_id_endpoint)
swagger_dict = swagger_spec.get_spec_as_dict()
yaml.Dumper.ignore_aliases = lambda *args : True
with open(SwaggerGenerator.FILE_PATH, "w+") as target:
target.write(self.get_yaml_top())
target.write(self.get_yaml_paths())
target.write(yaml.dump(swagger_dict))
target.close()


Expand Down

0 comments on commit 0f759ba

Please sign in to comment.