def update_role_groups(self, role_id):
        """Update role groups
        ---
        put:
          parameters:
          - in: path
            schema:
              type: integer
            name: role_id
          requestBody:
            description: Update role groups schema
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/RoleGroupPutSchema'
          responses:
            200:
              description: Role groups updated
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      result:
                        $ref: '#/components/schemas/RoleGroupPutSchema'
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            404:
              $ref: '#/components/responses/404'
            422:
              $ref: '#/components/responses/422'
            500:
              $ref: '#/components/responses/500'
        """
        try:
            item = self.update_role_group_schema.load(request.json)
            role = self.datamodel.get(role_id)
            if not role:
                return self.response_404()

            groups = (
                current_app.appbuilder.get_session.query(Group)
                .filter(Group.id.in_(item["group_ids"]))
                .all()
            )

            if len(groups) != len(item["group_ids"]):
                return self.response_404()  # Some groups were not found

            role.groups = groups
            self.datamodel.edit(role, raise_exception=True)
            return self.response(
                200,
                **{
                    API_RESULT_RES_KEY: self.update_role_group_schema.dump(
                        item, many=False
                    )
                },
            )

        except ValidationError as error:
            return self.response_400(message=error.messages)
        except IntegrityError as e:
            return self.response_422(message=str(e.orig))
Update role groups
        ---
        put:
          parameters:
          - in: path
            schema:
              type: integer
            name: role_id
          requestBody:
            description: Update role groups schema
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/RoleGroupPutSchema'
          responses:
            200:
              description: Role groups updated
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      result:
                        $ref: '#/components/schemas/RoleGroupPutSchema'
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            404:
              $ref: '#/components/responses/404'
            422:
              $ref: '#/components/responses/422'
            500:
              $ref: '#/components/responses/500'
        
flask_appbuilder/security/sqla/apis/role/api.py