Skip to content

Commit

Permalink
#119: Fix OpenAPI docs for related entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Feb 2, 2021
1 parent fc73642 commit 346731c
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 206 deletions.
16 changes: 12 additions & 4 deletions datagateway_api/src/resources/entities/entity_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,25 @@ def create_entity_models():
or relationship_class.direction.name == "ONETOONE"
):
params[relationship_name] = {
"$ref": f"#/components/schemas/{relationship_name.strip('_')}",
"$ref": "#/components/schemas/"
f"{relationship_name.strip('_').upper()}",
}
if (
relationship_class.direction.name == "MANYTOMANY"
or relationship_class.direction.name == "ONETOMANY"
):
entity_underscore_strip = relationship_name.strip("_")
if entity_underscore_strip[-1] == "s":
pascal_case = (
entity_underscore_strip[0].upper() + entity_underscore_strip[1:]
)
entity_reference_name = endpoints[pascal_case].upper()
else:
entity_reference_name = relationship_name.strip("_").upper()

params[relationship_name] = {
"type": "array",
"items": {
"$ref": f"#/components/schemas/{relationship_name.strip('_')}",
},
"items": {"$ref": f"#/components/schemas/{entity_reference_name}"},
}
endpoint_models[endpoint_table.__name__] = {
"properties": params,
Expand Down
Loading

0 comments on commit 346731c

Please sign in to comment.