docstr: Add tags to an object. Create new tags if they do not already exist.
  ---
  post:
    summary: Add tags to an object
    description: >-
      Adds tags to an object. Creates new tags if they do not already exist.
    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
    parameters:
    - in: path
      schema:
        type: integer
      name: object_type
    - in: path
      schema:
        type: integer
      name: object_id
    responses:
      201:
        description: Tag added
      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'
docstr_tok: ["Add","tags","to","an","object",".","Create","new","tags","if","they","do","not","already","exist",".","--","-","post",":","summary",":","Add","tags","to","an","object","description",":",">","-","Adds","tags","to","an","object",".","Creates","new","tags","if","they","do","not","already","exist",".","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","parameters",":","-","in",":","path","schema",":","type",":","integer","name",":","object_type","-","in",":","path","schema",":","type",":","integer","name",":","object_id","responses",":","201",":","description",":","Tag","added","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","'"]
code: def add_objects(
      self, object_type: ObjectType, object_id: int
  ) -> Response:
      """Add tags to an object. Create new tags if they do not already exist.
      ---
      post:
        summary: Add tags to an object
        description: >-
          Adds tags to an object. Creates new tags if they do not already exist.
        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
        parameters:
        - in: path
          schema:
            type: integer
          name: object_type
        - in: path
          schema:
            type: integer
          name: object_id
        responses:
          201:
            description: Tag added
          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'
      """
      try:
          tags = request.json["properties"]["tags"]
          # This validates custom Schema with custom validations
          CreateCustomTagCommand(object_type, object_id, tags).run()
          return self.response(201)
      except KeyError:
          return self.response(
              400,
              message="Missing required field 'tags' in 'properties'",
          )
      except TagInvalidError:
          return self.response(422, message="Invalid tag")
  
imports: import logging
  from typing import Any
  from flask import request, Response
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from marshmallow import ValidationError
  from superset.commands.tag.create import CreateCustomTagCommand, CreateCustomTagWithRelationshipsCommand
  from superset.commands.tag.delete import DeleteTaggedObjectCommand, DeleteTagsCommand
  from superset.commands.tag.exceptions import TagDeleteFailedError, TaggedObjectDeleteFailedError, TaggedObjectNotFoundError, TagInvalidError, TagNotFoundError, TagUpdateFailedError
  from superset.commands.tag.update import UpdateTagCommand
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.daos.tag import TagDAO
  from superset.exceptions import MissingUserContextException
  from superset.extensions import event_logger
  from superset.tags.models import ObjectType, Tag
  from superset.tags.schemas import delete_tags_schema, openapi_spec_methods_override, TaggedObjectEntityResponseSchema, TagGetResponseSchema, TagPostBulkSchema, TagPostSchema, TagPutSchema
  from superset.views.base_api import BaseSupersetModelRestApi, RelatedFieldFilter, statsd_metrics
  from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners
label_desc: Use image node_id 5 for calling the TagRestApi obj's underlying member method code with example usage: obj.add_objects(object_type, object_id) and returns: self, self, self