Skip to content

Commit

Permalink
Use schemas and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeopti committed Sep 2, 2021
1 parent da319a6 commit e68f310
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions terracotta/server/valid_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,34 @@ def list_items(self, data: Dict[str, Any], **kwargs: Any) -> Dict[str, Union[str
return data


class KeyValueSchema(Schema):
valid_values = fields.Dict(
key=fields.String(example='key1'),
values=fields.List(fields.String(example='value1')),
required=True,
description='Array containing all available key combinations'
)


@METADATA_API.route('/valid_values', methods=['GET'])
def get_valid_values() -> Response:
"""Get all valid values combinations (possibly when given a value for some keys)
---
get:
summary: /datasets
description:
Get keys of all available datasets that match given key constraint.
Constraints may be combined freely. Returns all known datasets if no query parameters
Get uniwue key values of all available datasets that match given key constraint.
Constraints may be combined freely. Returns all valid key values if no query parameters
are given.
parameters:
- in: query
schema: DatasetOptionSchema
schema: KeyValueOptionSchema
responses:
200:
description: All available key combinations
schema:
type: array
items: DatasetSchema
items: KeyValueSchema
400:
description: Query parameters contain unrecognized keys
"""
Expand All @@ -60,4 +69,5 @@ def get_valid_values() -> Response:
'valid_values': valid_values(keys)
}

return jsonify(payload)
schema = KeyValueSchema()
return jsonify(schema.load(payload))

0 comments on commit e68f310

Please sign in to comment.