From ecb85f04530d316f55c909d165e75edf15ecb6ad Mon Sep 17 00:00:00 2001 From: Keith Mitchell Date: Fri, 28 Mar 2014 13:37:51 -0700 Subject: [PATCH] /dev/api: Fix docs for /api/v1/me/prefs --- r2/r2/controllers/apiv1.py | 5 +++-- r2/r2/lib/validator/validator.py | 15 +++++++++++++++ r2/r2/templates/apihelp.html | 10 +++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/r2/r2/controllers/apiv1.py b/r2/r2/controllers/apiv1.py index 743ff9a79..689c9d19b 100644 --- a/r2/r2/controllers/apiv1.py +++ b/r2/r2/controllers/apiv1.py @@ -73,7 +73,7 @@ class APIv1Controller(OAuth2ResourceController): return self.api_wrapper(resp) @require_oauth2_scope("identity") - @api_doc(api_section.account) + @api_doc(api_section.account, uri='/api/v1/me/prefs') @validate( fields=VList( "fields", @@ -90,7 +90,8 @@ class APIv1Controller(OAuth2ResourceController): body=True) @require_oauth2_scope("account") - @api_doc(api_section.account, json_model=PREFS_JSON_VALIDATOR) + @api_doc(api_section.account, json_model=PREFS_JSON_VALIDATOR, + uri='/api/v1/me/prefs') @validate(validated_prefs=PREFS_JSON_VALIDATOR) def PATCH_prefs(self, validated_prefs): user_prefs = c.user.preferences() diff --git a/r2/r2/lib/validator/validator.py b/r2/r2/lib/validator/validator.py index c3be3d254..b99b61f1c 100644 --- a/r2/r2/lib/validator/validator.py +++ b/r2/r2/lib/validator/validator.py @@ -1786,6 +1786,21 @@ class VList(Validator): code=400) return values + # Not i18n'able, but param_docs are not currently i18n'ed + NICE_SEP = {",": "comma"} + def param_docs(self): + if self.choices: + msg = ("A %(separator)s-separated list of items from " + "this set:\n\n%(choices)s") + choices = "`" + "` \n`".join(self.choices) + "`" + else: + msg = "A %(separator)s-separated list of items" + choices = None + + sep = self.NICE_SEP.get(self.separator, self.separator) + docs = msg % {"separator": sep, "choices": choices} + return {self.param: docs} + class VPriority(Validator): def run(self, val): diff --git a/r2/r2/templates/apihelp.html b/r2/r2/templates/apihelp.html index 1e0dbbd05..79889846a 100644 --- a/r2/r2/templates/apihelp.html +++ b/r2/r2/templates/apihelp.html @@ -252,9 +252,13 @@ example, `t3_15bfi0`.
${unsafe(safemarkdown(docs.get('doc')))} <% - params = docs.get('parameters') - base_params = extends.get('parameters') if extends else None json_model = docs.get('json_model') + if json_model: + params = None + base_params = None + else: + params = docs.get('parameters') + base_params = extends.get('parameters') if extends else None %> %if params or base_params or json_model: @@ -278,7 +282,7 @@ example, `t3_15bfi0`. %endif %if json_model: - + %endif
${_("This endpoint expects JSON data using this model")}${_("This endpoint expects JSON data of this format")} ${unsafe(safemarkdown(json_model.docs_model(), wrap=False))}