From aaad5e8f2b5d944ba3662d3295b2bd06db6f9ae3 Mon Sep 17 00:00:00 2001 From: militarpancho Date: Thu, 13 Jul 2017 13:35:56 +0200 Subject: [PATCH] Add 'help' as a parameter to the API, with two options: "true" and "false". It is false by default. Modify all the /api blueprint to export the list of available params --- senpy/api.py | 8 ++++++++ senpy/blueprints.py | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/senpy/api.py b/senpy/api.py index 886901b..14ad069 100644 --- a/senpy/api.py +++ b/senpy/api.py @@ -39,6 +39,14 @@ API_PARAMS = { "required": True, "options": ["filtered", "nested", "full"], "default": "full" + }, + "help": { + "@id": "help", + "description": "Show additional help to know more about the possible parameters", + "aliases": ["help", "h"], + "required": True, + "options": ["True", "False"], + "default": "False" } } diff --git a/senpy/blueprints.py b/senpy/blueprints.py index 4dcc9ce..26c91a9 100644 --- a/senpy/blueprints.py +++ b/senpy/blueprints.py @@ -20,7 +20,7 @@ Blueprints for Senpy from flask import (Blueprint, request, current_app, render_template, url_for, jsonify) from .models import Error, Response, Plugins, read_schema -from .api import WEB_PARAMS, API_PARAMS, parse_params +from .api import WEB_PARAMS, API_PARAMS, CLI_PARAMS, NIF_PARAMS, parse_params from .version import __version__ from functools import wraps @@ -144,3 +144,21 @@ def plugin(plugin=None): else: return Error(message="Plugin not found", status=404) return response + +@api_blueprint.route('/params/', methods=['POST', 'GET']) +@basic_api +def params(): + phelp = request.params.get('help') + if eval(phelp): + dic = {'WEB_PARAMS': WEB_PARAMS, + 'CLI_PARAMS': CLI_PARAMS, + 'NIF_PARAMS': NIF_PARAMS, + 'API_PARAMS': API_PARAMS + } + response = Response(dic) + return response + else: + response = Response(request.params) + return response + +