Skip to content

Commit

Permalink
fix: advanced data type API spec and permission name (apache#20128)
Browse files Browse the repository at this point in the history
* fix: advanced data type API spec and permission name

* fix openAPI spec

* fix query schema

* fix query schema

* fix query schema
  • Loading branch information
dpgaspar authored and philipher29 committed Jun 9, 2022
1 parent 319f12f commit 11d0674
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
44 changes: 16 additions & 28 deletions superset/advanced_data_type/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from flask_appbuilder.api import BaseApi, expose, permission_name, protect, rison, safe
from flask_babel import lazy_gettext as _

from superset.advanced_data_type.schemas import advanced_data_type_convert_schema
from superset.advanced_data_type.schemas import (
advanced_data_type_convert_schema,
AdvancedDataTypeSchema,
)
from superset.advanced_data_type.types import AdvancedDataTypeResponse
from superset.extensions import event_logger

Expand All @@ -40,26 +43,28 @@ class AdvancedDataTypeRestApi(BaseApi):
allow_browser_login = True
include_route_methods = {"get", "get_types"}
resource_name = "advanced_data_type"
class_permission_name = "AdvancedDataType"

openapi_spec_tag = "Advanced Data Type"
apispec_parameter_schemas = {
"advanced_data_type_convert_schema": advanced_data_type_convert_schema,
}
openapi_spec_component_schemas = (AdvancedDataTypeSchema,)

@protect()
@safe
@expose("/convert", methods=["GET"])
@permission_name("get")
@permission_name("read")
@event_logger.log_this_with_context(
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.get",
log_to_statsd=False, # pylint: disable-arguments-renamed
)
@rison()
@rison(advanced_data_type_convert_schema)
def get(self, **kwargs: Any) -> Response:
"""Returns a AdvancedDataTypeResponse object populated with the passed in args
---
get:
description: >-
summary: >-
Returns a AdvancedDataTypeResponse object populated with the passed in args.
parameters:
- in: query
Expand All @@ -75,18 +80,7 @@ def get(self, **kwargs: Any) -> Response:
content:
application/json:
schema:
type: object
properties:
status:
type: string
values:
type: array
formatted_value:
type: string
error_message:
type: string
valid_filter_operators:
type: string
$ref: '#/components/schemas/AdvancedDataTypeSchema'
400:
$ref: '#/components/responses/400'
401:
Expand All @@ -96,15 +90,9 @@ def get(self, **kwargs: Any) -> Response:
500:
$ref: '#/components/responses/500'
"""
items = kwargs["rison"]
advanced_data_type = items.get("type")
if not advanced_data_type:
return self.response(
400, message=_("Missing advanced data type in request")
)
values = items["values"]
if not values:
return self.response(400, message=_("Missing values in request"))
item = kwargs["rison"]
advanced_data_type = item["type"]
values = item["values"]
addon = ADVANCED_DATA_TYPES.get(advanced_data_type)
if not addon:
return self.response(
Expand All @@ -124,7 +112,7 @@ def get(self, **kwargs: Any) -> Response:
@protect()
@safe
@expose("/types", methods=["GET"])
@permission_name("get")
@permission_name("read")
@event_logger.log_this_with_context(
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.get",
log_to_statsd=False, # pylint: disable-arguments-renamed
Expand All @@ -147,8 +135,8 @@ def get_types(self) -> Response:
properties:
result:
type: array
400:
$ref: '#/components/responses/400'
items:
type: string
401:
$ref: '#/components/responses/401'
404:
Expand Down
28 changes: 22 additions & 6 deletions superset/advanced_data_type/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@
"""
Schemas for advanced data types
"""
from marshmallow import fields, Schema

advanced_data_type_convert_schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {"type": "string"},
"values": {"type": "array"},
"type": "object",
"properties": {
"type": {"type": "string", "default": "port"},
"values": {
"type": "array",
"items": {"default": "http"},
"minItems": 1,
},
},
"required": ["type", "values"],
}


class AdvancedDataTypeSchema(Schema):
"""
AdvancedDataType response schema
"""

error_message = fields.String()
values = fields.List(fields.String(description="parsed value (can be any value)"))
display_value = fields.String(
description="The string representation of the parsed values"
)
valid_filter_operators = fields.List(fields.String())

0 comments on commit 11d0674

Please sign in to comment.