예제 #1
0
파일: api.py 프로젝트: ws1993/superset
 def post(self) -> Response:
     """Creates a new Dashboard
     ---
     post:
       description: >-
         Create a new Dashboard.
       requestBody:
         description: Dashboard schema
         required: true
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/{{self.__class__.__name__}}.post'
       responses:
         201:
           description: Dashboard added
           content:
             application/json:
               schema:
                 type: object
                 properties:
                   id:
                     type: number
                   result:
                     $ref: '#/components/schemas/{{self.__class__.__name__}}.post'
         302:
           description: Redirects to the current digest
         400:
           $ref: '#/components/responses/400'
         401:
           $ref: '#/components/responses/401'
         404:
           $ref: '#/components/responses/404'
         500:
           $ref: '#/components/responses/500'
     """
     if not request.is_json:
         return self.response_400(message="Request is not JSON")
     try:
         item = self.add_model_schema.load(request.json)
     # This validates custom Schema with custom validations
     except ValidationError as error:
         return self.response_400(message=error.messages)
     try:
         new_model = CreateDashboardCommand(g.user, item).run()
         return self.response(201, id=new_model.id, result=item)
     except DashboardInvalidError as ex:
         return self.response_422(message=ex.normalized_messages())
     except DashboardCreateFailedError as ex:
         logger.error(
             "Error creating model %s: %s",
             self.__class__.__name__,
             str(ex),
             exc_info=True,
         )
         return self.response_422(message=str(ex))
예제 #2
0
 def post(self) -> Response:
     """Creates a new Dashboard
     ---
     post:
       description: >-
         Create a new Dashboard
       requestBody:
         description: Dashboard schema
         required: true
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/{{self.__class__.__name__}}.post'
       responses:
         201:
           description: Dashboard added
           content:
             application/json:
               schema:
                 type: object
                 properties:
                   id:
                     type: number
                   result:
                     $ref: '#/components/schemas/{{self.__class__.__name__}}.post'
         400:
           $ref: '#/components/responses/400'
         401:
           $ref: '#/components/responses/401'
         422:
           $ref: '#/components/responses/422'
         500:
           $ref: '#/components/responses/500'
     """
     if not request.is_json:
         return self.response_400(message="Request is not JSON")
     item = self.add_model_schema.load(request.json)
     # This validates custom Schema with custom validations
     if item.errors:
         return self.response_400(message=item.errors)
     try:
         new_model = CreateDashboardCommand(g.user, item.data).run()
         return self.response(201, id=new_model.id, result=item.data)
     except DashboardInvalidError as e:
         return self.response_422(message=e.normalized_messages())
     except DashboardCreateFailedError as e:
         logger.error(
             f"Error creating model {self.__class__.__name__}: {e}")
         return self.response_422(message=str(e))