Skip to content

Commit

Permalink
Include 'findone' endpoints in generated openapi.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartpullinger committed Nov 22, 2019
1 parent bb164ae commit bc55c74
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/swagger/swagger_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,41 @@ def __init__(self, entity_name, model):
}
}
}
self.entity_findone_endpoint = {
f"/{entity_name.lower()}/findone": {
"get": {
"summary": f"Get one {SwaggerGenerator.singularise(entity_name).lower()} entity based on filters",
"tags": ["entities"],
"parameters": [self.WHERE_PARAMETER,
self.DISTINCT_PARAMETER,
self.INCLUDE_PARAMETER,
self.LIMIT_PARAMETER,
self.ORDER_PARAMETER,
self.SKIP_PARAMETER],
"responses": {
"200": {
"description": f"The first {SwaggerGenerator.singularise(entity_name).lower()} entity found",
"content": {
"application/json": {
"schema": {
"$ref": f"#/components/schemas/{SwaggerGenerator.singularise(entity_name)}"
}
}
}
},
"404": {
"description": "When no results are found"
},
"401": {
"description": "When no credentials are provided"
},
"403": {
"description": "When bad credentials are provided"
}
}
}
}
}


class SwaggerSpecification(object):
Expand All @@ -266,7 +301,7 @@ def __init__(self):
],
"paths": {},
"components": {
"schemas":{}
"schemas": {}
}
}

Expand Down Expand Up @@ -302,7 +337,7 @@ def pascal_to_normal(input):
return " ".join(map(str.lower, words))

@staticmethod
def singularise(plural_word:str):
def singularise(plural_word: str):
if plural_word.lower().endswith('ies'):
singular_word = plural_word[:-3] + ('Y' if plural_word.isupper() else 'y')
elif plural_word.lower().endswith('s'):
Expand All @@ -323,6 +358,7 @@ def write_swagger_spec(self):
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_spec.add_path(entity.entity_findone_endpoint)
swagger_spec.add_schema(entity.entity_schema)
swagger_dict = swagger_spec.get_spec_as_dict()
yaml.Dumper.ignore_aliases = lambda *args: True
Expand Down

0 comments on commit bc55c74

Please sign in to comment.