fix(tags): clean up bulk create api and schema (#31427)

This commit is contained in:
Ville Brofeldt 2024-12-12 17:54:10 -08:00 committed by GitHub
parent cd200f07a5
commit bf56a327f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5118 additions and 933 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,7 @@ from superset.tags.schemas import (
openapi_spec_methods_override,
TaggedObjectEntityResponseSchema,
TagGetResponseSchema,
TagPostBulkResponseSchema,
TagPostBulkSchema,
TagPostSchema,
TagPutSchema,
@ -132,6 +133,8 @@ class TagRestApi(BaseSupersetModelRestApi):
openapi_spec_component_schemas = (
TagGetResponseSchema,
TaggedObjectEntityResponseSchema,
TagPostBulkResponseSchema,
TagPostBulkSchema,
)
apispec_parameter_schemas = {
"delete_tags_schema": delete_tags_schema,
@ -211,40 +214,21 @@ class TagRestApi(BaseSupersetModelRestApi):
"""Bulk create tags and tagged objects
---
post:
summary: Get all objects associated with a tag
parameters:
- in: path
schema:
type: integer
name: tag_id
summary: Bulk create tags and tagged objects
requestBody:
description: Tag schema
required: true
content:
application/json:
schema:
type: object
properties:
tags:
description: list of tag names to add to object
type: array
items:
type: string
objects_to_tag:
description: list of object names to add to object
type: array
items:
type: array
$ref: '#/components/schemas/TagPostBulkSchema'
responses:
200:
description: Tag added to favorites
description: Bulk created tags and tagged objects
content:
application/json:
schema:
type: object
properties:
result:
type: object
$ref: '#/components/schemas/TagPostBulkResponseSchema'
302:
description: Redirects to the current digest
400:
@ -267,6 +251,7 @@ class TagRestApi(BaseSupersetModelRestApi):
tagged_item: dict[str, Any] = self.add_model_schema.load(
{
"name": tag.get("name"),
"description": tag.get("description"),
"objects_to_tag": tag.get("objects_to_tag"),
}
)

View File

@ -53,21 +53,41 @@ class TaggedObjectEntityResponseSchema(Schema):
changed_on = fields.DateTime()
created_by = fields.Nested(UserSchema(exclude=["username"]))
creator = fields.String()
tags = fields.List(fields.Nested(TagGetResponseSchema))
owners = fields.List(fields.Nested(UserSchema))
tags = fields.List(fields.Nested(TagGetResponseSchema()))
owners = fields.List(fields.Nested(UserSchema()))
objects_to_tag_field = fields.List(
fields.Tuple(
(
fields.String(metadata={"description": "type of resource"}),
fields.Int(validate=Range(min=1), metadata={"description": "resource id"}),
),
),
metadata={
"description": "Objects to tag",
},
required=False,
)
class TagObjectSchema(Schema):
name = fields.String(validate=Length(min=1))
description = fields.String(required=False, allow_none=True)
objects_to_tag = fields.List(
fields.Tuple((fields.String(), fields.Int(validate=Range(min=1)))),
required=False,
)
objects_to_tag = objects_to_tag_field
class TagPostBulkSchema(Schema):
tags = fields.List(fields.Nested(TagObjectSchema))
tags = fields.List(fields.Nested(TagObjectSchema()))
class TagPostBulkResponseObjectSchema(Schema):
objects_tagged = objects_to_tag_field
objects_skipped = objects_to_tag_field
class TagPostBulkResponseSchema(Schema):
result = fields.Nested(TagPostBulkResponseObjectSchema())
class TagPostSchema(TagObjectSchema):