From 6b76520cc7a36505b1e2c7983dd371a3e08c0878 Mon Sep 17 00:00:00 2001 From: esensar Date: Sun, 23 Sep 2018 13:56:41 +0200 Subject: [PATCH] Fix swagger roles issue --- app/api/resources/account.py | 4 ++-- .../resources/swagger/create_role_spec.yaml | 19 +++++++++++++++++ app/api/resources/swagger/get_role_spec.yaml | 21 +++++++++++++++++++ app/api/resources/swagger/get_roles_spec.yaml | 16 ++++++++++++++ app/swagger/template.yaml | 21 +++++++++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 app/api/resources/swagger/create_role_spec.yaml create mode 100644 app/api/resources/swagger/get_role_spec.yaml create mode 100644 app/api/resources/swagger/get_roles_spec.yaml diff --git a/app/api/resources/account.py b/app/api/resources/account.py index c14f13e..382f46b 100644 --- a/app/api/resources/account.py +++ b/app/api/resources/account.py @@ -18,7 +18,7 @@ class RoleUpdateSchema(Schema): class RoleSchema(Schema): - role_id = fields.Integer(required=True, location='json') + id = fields.Integer(required=True, location='json') display_name = fields.String(required=True, location='json') permissions = fields.List(fields.String, required=True, location='json', many=True) @@ -63,9 +63,9 @@ class RoleResource(ProtectedResource): class RolesResource(ProtectedResource): + @requires_permission('CREATE_ROLE', 'Role creation') @use_args(RoleCreationWrapperSchema()) @swag_from('swagger/create_role_spec.yaml') - @requires_permission('CREATE_ROLE', 'Role creation') def post(self, args): args = args['role'] success = accounts.create_role(args['display_name'], diff --git a/app/api/resources/swagger/create_role_spec.yaml b/app/api/resources/swagger/create_role_spec.yaml new file mode 100644 index 0000000..2ca95d8 --- /dev/null +++ b/app/api/resources/swagger/create_role_spec.yaml @@ -0,0 +1,19 @@ +Creates new role +Requires Role object and creates role +--- +tags: + - Role +parameters: + - in: body + name: body + required: true + schema: + type: object + required: + - role + properties: + device: + $ref: '#/definitions/Role' +responses: + 201: + description: Successful creation diff --git a/app/api/resources/swagger/get_role_spec.yaml b/app/api/resources/swagger/get_role_spec.yaml new file mode 100644 index 0000000..38defde --- /dev/null +++ b/app/api/resources/swagger/get_role_spec.yaml @@ -0,0 +1,21 @@ +Gets a role +--- +tags: + - Role +parameters: + - in: path + name: role_id + required: true + type: integer + description: Id of the role +responses: + 200: + description: Success + schema: + type: object + required: + - role + properties: + device: + $ref: '#/definitions/Role' + diff --git a/app/api/resources/swagger/get_roles_spec.yaml b/app/api/resources/swagger/get_roles_spec.yaml new file mode 100644 index 0000000..6c8f87a --- /dev/null +++ b/app/api/resources/swagger/get_roles_spec.yaml @@ -0,0 +1,16 @@ +Gets all roles +--- +tags: + - Role +responses: + 200: + description: Success + schema: + type: object + required: + - roles + properties: + devices: + type: array + items: + $ref: '#/definitions/Role' diff --git a/app/swagger/template.yaml b/app/swagger/template.yaml index b2827a5..e97a4fb 100644 --- a/app/swagger/template.yaml +++ b/app/swagger/template.yaml @@ -7,6 +7,11 @@ basePath: "" definitions: + genericname: + type: string + description: name + default: name + username: type: string description: User's name in the system @@ -91,6 +96,22 @@ definitions: email: $ref: '#/definitions/email' + Role: + type: object + required: + - id + - display_name + - permissions + properties: + id: + $ref: '#/definitions/id' + display_name: + $ref: '#/definitions/genericname' + permissions: + type: array + items: + $ref: '#definitions/genericname' + Recording: type: object required: