From e68f3106fd4c2eed66714ae341d2187597e349a4 Mon Sep 17 00:00:00 2001 From: NNicklas Boserup Date: Thu, 2 Sep 2021 11:31:01 +0200 Subject: [PATCH] Use schemas and update documentation --- terracotta/server/valid_values.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/terracotta/server/valid_values.py b/terracotta/server/valid_values.py index c33442b5..e4d92f03 100644 --- a/terracotta/server/valid_values.py +++ b/terracotta/server/valid_values.py @@ -28,6 +28,15 @@ 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) @@ -35,18 +44,18 @@ def get_valid_values() -> Response: 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 """ @@ -60,4 +69,5 @@ def get_valid_values() -> Response: 'valid_values': valid_values(keys) } - return jsonify(payload) + schema = KeyValueSchema() + return jsonify(schema.load(payload))