docstr: Format the SQL query.
  ---
  post:
    summary: Format SQL code
    requestBody:
      description: SQL query
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/FormatQueryPayloadSchema'
    responses:
      200:
        description: Format SQL result
        content:
          application/json:
            schema:
              type: object
              properties:
                result:
                  type: string
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      403:
        $ref: '#/components/responses/403'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Format","the","SQL","query",".","--","-","post",":","summary",":","Format","SQL","code","requestBody",":","description",":","SQL","query","required",":","true","content",":","application\/json",":","schema",":","$","ref",":","'","#","\/components\/schemas\/FormatQueryPayloadSchema'","responses",":","200",":","description",":","Format","SQL","result","content",":","application\/json",":","schema",":","type",":","object","properties",":","result",":","type",":","string","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","403",":","$","ref",":","'","#","\/components\/responses\/403'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def format_sql(self) -> FlaskResponse:
      """Format the SQL query.
      ---
      post:
        summary: Format SQL code
        requestBody:
          description: SQL query
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FormatQueryPayloadSchema'
        responses:
          200:
            description: Format SQL result
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    result:
                      type: string
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          403:
            $ref: '#/components/responses/403'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          model = self.format_model_schema.load(request.json)
          result = sqlparse.format(
              model["sql"], reindent=True, keyword_case="upper"
          )
          return self.response(200, result=result)
      except ValidationError as error:
          return self.response_400(message=error.messages)
  
imports: import logging
  from typing import Any, cast, Optional
  from urllib import parse
  import simplejson
  import sqlparse
  from flask import request, Response
  from flask_appbuilder import permission_name
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from marshmallow import ValidationError
  from superset import app, is_feature_enabled
  from superset.commands.sql_lab.estimate import QueryEstimationCommand
  from superset.commands.sql_lab.execute import CommandResult, ExecuteSqlCommand
  from superset.commands.sql_lab.export import SqlResultExportCommand
  from superset.commands.sql_lab.results import SqlExecutionResultsCommand
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP
  from superset.daos.database import DatabaseDAO
  from superset.daos.query import QueryDAO
  from superset.extensions import event_logger
  from superset.jinja_context import get_template_processor
  from superset.models.sql_lab import Query
  from superset.sql_lab import get_sql_results
  from superset.sqllab.command_status import SqlJsonExecutionStatus
  from superset.sqllab.exceptions import QueryIsForbiddenToAccessException, SqlLabException
  from superset.sqllab.execution_context_convertor import ExecutionContextConvertor
  from superset.sqllab.query_render import SqlQueryRenderImpl
  from superset.sqllab.schemas import EstimateQueryCostSchema, ExecutePayloadSchema, FormatQueryPayloadSchema, QueryExecutionResponseSchema, sql_lab_get_results_schema, SQLLabBootstrapSchema
  from superset.sqllab.sql_json_executer import ASynchronousSqlJsonExecutor, SqlJsonExecutor, SynchronousSqlJsonExecutor
  from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext
  from superset.sqllab.utils import bootstrap_sqllab_data
  from superset.sqllab.validators import CanAccessQueryValidatorImpl
  from superset.superset_typing import FlaskResponse
  from superset.utils import core
  from superset.views.base import CsvResponse, generate_download_headers, json_success
  from superset.views.base_api import BaseSupersetApi, requires_json, statsd_metrics
label_desc: Use image node_id 3 for calling the SqlLabRestApi obj's underlying member method code with example usage: obj.format_sql() and returns: self, self