Skip to content

Commit

Permalink
Add response schema
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Apr 6, 2021
1 parent c11d9d1 commit cded967
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
49 changes: 49 additions & 0 deletions superset/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from superset.errors import SupersetErrorType

error_payload_content = {
"application/json": {
"schema": {
"type": "object",
"properties": {
# SIP-40 error payload
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {"type": "string"},
"error_type": {
"type": "string",
"enum": [enum.value for enum in SupersetErrorType],
},
"level": {
"type": "string",
"enum": ["info", "warning", "error"],
},
"extra": {"type": "object"},
},
},
},
# Old-style message payload
"message": {"type": "string"},
},
},
},
}
13 changes: 13 additions & 0 deletions superset/views/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from superset.models.core import FavStar
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from superset.schemas import error_payload_content
from superset.sql_lab import Query as SqllabQuery
from superset.stats_logger import BaseStatsLogger
from superset.typing import FlaskResponse
Expand Down Expand Up @@ -198,6 +199,18 @@ class BaseSupersetModelRestApi(ModelRestApi):
list_columns: List[str]
show_columns: List[str]

responses = {
"400": {"description": "Bad request", "content": error_payload_content},
"401": {"description": "Unauthorized", "content": error_payload_content},
"403": {"description": "Forbidden", "content": error_payload_content},
"404": {"description": "Not found", "content": error_payload_content},
"422": {
"description": "Could not process entity",
"content": error_payload_content,
},
"500": {"description": "Fatal error", "content": error_payload_content},
}

def __init__(self) -> None:
# Setup statsd
self.stats_logger = BaseStatsLogger()
Expand Down

0 comments on commit cded967

Please sign in to comment.