Skip to content

Commit

Permalink
Merge pull request #178 from ral-facilities/feature/fix-swagger-data-…
Browse files Browse the repository at this point in the history
…parsing-#166

Update Swagger/OpenAPI Docs for New Backend
  • Loading branch information
MRichards99 authored Dec 2, 2020
2 parents b12e7cd + 588158c commit 864e020
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 145 deletions.
2 changes: 2 additions & 0 deletions common/database/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def apply_filter(self, query):

if self.operation == "eq":
query.base_query = query.base_query.filter(field == self.value)
elif self.operation == "ne":
query.base_query = query.base_query.filter(field != self.value)
elif self.operation == "like":
query.base_query = query.base_query.filter(field.like(f"%{self.value}%"))
elif self.operation == "lt":
Expand Down
6 changes: 3 additions & 3 deletions src/resources/entities/entity_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get(self, id_):
parameters:
- in: path
required: true
name: id
name: id_
description: The id of the entity to retrieve
schema:
type: integer
Expand Down Expand Up @@ -213,7 +213,7 @@ def delete(self, id_):
parameters:
- in: path
required: true
name: id
name: id_
description: The id of the entity to delete
schema:
type: integer
Expand Down Expand Up @@ -244,7 +244,7 @@ def patch(self, id_):
parameters:
- in: path
required: true
name: id
name: id_
description: The id of the entity to update
schema:
type: integer
Expand Down
4 changes: 2 additions & 2 deletions src/resources/table_endpoints/table_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get(self, id_):
parameters:
- in: path
required: true
name: id
name: id_
description: The id of the instrument to retrieve the facility cycles of
schema:
type: integer
Expand Down Expand Up @@ -71,7 +71,7 @@ def get(self, id_):
parameters:
- in: path
required: true
name: id
name: id_
description: The id of the instrument to count the facility cycles of
schema:
type: integer
Expand Down
63 changes: 52 additions & 11 deletions src/swagger/initialise_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialise_spec(spec):
{
"in": "query",
"name": "where",
"description": "Apply where filters to the query. The possible operators are like, gte, lte, in and eq",
"description": "Apply where filters to the query. The possible operators are like, gte, lte, in and eq. Please modify the examples before executing a request if you are having issues with the example values.",
"schema": {
"type": "array",
"items": {
Expand Down Expand Up @@ -53,9 +53,28 @@ def initialise_spec(spec):
},
{
"type": "object",
"title": "Greater than or equal",
"title": "Inequality",
"properties": {
"gte": {
"ne": {
"oneOf": [
{"type": "string"},
{"type": "number"},
{"type": "integer"},
{"type": "boolean"},
]
}
},
},
{
"type": "object",
"title": "Substring equality",
"properties": {"like": {"type": "string"}},
},
{
"type": "object",
"title": "Less than",
"properties": {
"lt": {
"oneOf": [
{"type": "number"},
{"type": "integer"},
Expand All @@ -77,8 +96,27 @@ def initialise_spec(spec):
},
{
"type": "object",
"title": "Substring equality",
"properties": {"like": {"type": "string"}},
"title": "Greater than",
"properties": {
"gt": {
"oneOf": [
{"type": "number"},
{"type": "integer"},
]
}
},
},
{
"type": "object",
"title": "Greater than or equal",
"properties": {
"gte": {
"oneOf": [
{"type": "number"},
{"type": "integer"},
]
}
},
},
{
"type": "object",
Expand All @@ -101,11 +139,14 @@ def initialise_spec(spec):
},
},
"examples": {
"eq": {"value": [{"ID": {"eq": 1}}]},
"like": {"value": [{"NAME": {"like": "dog"}}]},
"gte": {"value": [{"ID": {"gte": 50}}]},
"lte": {"value": [{"ID": {"lte": 50}}]},
"in": {"value": [{"ID": {"in": [1, 2, 3]}}]},
"eq": {"value": [{"id": {"eq": 1}}]},
"ne": {"value": [{"id": {"ne": 1}}]},
"like": {"value": [{"name": {"like": "dog"}}]},
"lt": {"value": [{"id": {"lt": 10}}]},
"lte": {"value": [{"id": {"lte": 50}}]},
"gt": {"value": [{"id": {"gt": 10}}]},
"gte": {"value": [{"id": {"gte": 50}}]},
"in": {"value": [{"id": {"in": [1, 2, 3]}}]},
},
},
)
Expand All @@ -118,7 +159,7 @@ def initialise_spec(spec):
"name": "order",
"description": "Apply order filters to the query. Given a field and direction, order the returned entities.",
"schema": {"type": "array", "items": {"type": "string"}},
"examples": {"asc": {"value": ["ID asc"]}, "desc": {"value": ["ID desc"]}},
"examples": {"asc": {"value": ["id asc"]}, "desc": {"value": ["id desc"]}},
},
)

Expand Down
Loading

0 comments on commit 864e020

Please sign in to comment.