Add path param description support
This commit is contained in:
parent
d9accd0593
commit
e0bb94e439
3 changed files with 25 additions and 2 deletions
|
@ -153,6 +153,18 @@ related_user_resource = partial(add_method_metadata, 'related_user_resource')
|
||||||
internal_only = add_method_metadata('internal', True)
|
internal_only = add_method_metadata('internal', True)
|
||||||
|
|
||||||
|
|
||||||
|
def path_param(name, description):
|
||||||
|
def add_param(func):
|
||||||
|
if '__api_path_params' not in dir(func):
|
||||||
|
func.__api_path_params = {}
|
||||||
|
func.__api_path_params[name] = {
|
||||||
|
'name': name,
|
||||||
|
'description': description
|
||||||
|
}
|
||||||
|
return func
|
||||||
|
return add_param
|
||||||
|
|
||||||
|
|
||||||
def query_param(name, help_str, type=reqparse.text_type, default=None,
|
def query_param(name, help_str, type=reqparse.text_type, default=None,
|
||||||
choices=(), required=False):
|
choices=(), required=False):
|
||||||
def add_param(func):
|
def add_param(func):
|
||||||
|
|
|
@ -39,6 +39,11 @@ def swagger_route_data(include_internal=False, compact=False):
|
||||||
|
|
||||||
if 'view_class' in dir(endpoint_method):
|
if 'view_class' in dir(endpoint_method):
|
||||||
view_class = endpoint_method.view_class
|
view_class = endpoint_method.view_class
|
||||||
|
|
||||||
|
param_data_map = {}
|
||||||
|
if '__api_path_params' in dir(view_class):
|
||||||
|
param_data_map = view_class.__api_path_params
|
||||||
|
|
||||||
operations = []
|
operations = []
|
||||||
|
|
||||||
method_names = list(rule.methods.difference(['HEAD', 'OPTIONS']))
|
method_names = list(rule.methods.difference(['HEAD', 'OPTIONS']))
|
||||||
|
@ -46,12 +51,13 @@ def swagger_route_data(include_internal=False, compact=False):
|
||||||
method = getattr(view_class, method_name.lower(), None)
|
method = getattr(view_class, method_name.lower(), None)
|
||||||
|
|
||||||
parameters = []
|
parameters = []
|
||||||
|
|
||||||
for param in rule.arguments:
|
for param in rule.arguments:
|
||||||
parameters.append({
|
parameters.append({
|
||||||
'paramType': 'path',
|
'paramType': 'path',
|
||||||
'name': param,
|
'name': param,
|
||||||
'dataType': 'string',
|
'dataType': 'string',
|
||||||
'description': 'Param description.',
|
'description': param_data_map.get(param, {'description': ''})['description'],
|
||||||
'required': True,
|
'required': True,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from endpoints.api import (resource, nickname, ApiResource, log_action, related_user_resource,
|
from endpoints.api import (resource, nickname, ApiResource, log_action, related_user_resource,
|
||||||
Unauthorized, require_user_admin, internal_only, require_scope)
|
Unauthorized, require_user_admin, internal_only, require_scope,
|
||||||
|
path_param)
|
||||||
from auth.permissions import AdministerOrganizationPermission, OrganizationMemberPermission
|
from auth.permissions import AdministerOrganizationPermission, OrganizationMemberPermission
|
||||||
from auth.auth_context import get_authenticated_user
|
from auth.auth_context import get_authenticated_user
|
||||||
from auth import scopes
|
from auth import scopes
|
||||||
|
@ -30,6 +31,7 @@ class UserRobotList(ApiResource):
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/user/robots/<robot_shortname>')
|
@resource('/v1/user/robots/<robot_shortname>')
|
||||||
|
@path_param('robot_shortname', 'The short name for the robot, without any user or organization prefix')
|
||||||
@internal_only
|
@internal_only
|
||||||
class UserRobot(ApiResource):
|
class UserRobot(ApiResource):
|
||||||
""" Resource for managing a user's robots. """
|
""" Resource for managing a user's robots. """
|
||||||
|
@ -53,6 +55,7 @@ class UserRobot(ApiResource):
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/organization/<orgname>/robots')
|
@resource('/v1/organization/<orgname>/robots')
|
||||||
|
@path_param('orgname', 'The name of the organization')
|
||||||
@related_user_resource(UserRobotList)
|
@related_user_resource(UserRobotList)
|
||||||
class OrgRobotList(ApiResource):
|
class OrgRobotList(ApiResource):
|
||||||
""" Resource for listing an organization's robots. """
|
""" Resource for listing an organization's robots. """
|
||||||
|
@ -71,6 +74,8 @@ class OrgRobotList(ApiResource):
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/organization/<orgname>/robots/<robot_shortname>')
|
@resource('/v1/organization/<orgname>/robots/<robot_shortname>')
|
||||||
|
@path_param('orgname', 'The name of the organization')
|
||||||
|
@path_param('robot_shortname', 'The short name for the robot, without any user or organization prefix')
|
||||||
@related_user_resource(UserRobot)
|
@related_user_resource(UserRobot)
|
||||||
class OrgRobot(ApiResource):
|
class OrgRobot(ApiResource):
|
||||||
""" Resource for managing an organization's robots. """
|
""" Resource for managing an organization's robots. """
|
||||||
|
|
Reference in a new issue