{
  "openapi": "3.1.1",
  "info": {
    "title": "Opsdeck SQL Formatter & Linter API",
    "version": "1.0.0",
    "summary": "Format SQL and catch UPDATE/DELETE without WHERE, SELECT * in views and cross joins.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://opsdecksqlformatter.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Format SQL and catch UPDATE/DELETE without WHERE, SELECT * in views and cross joins.",
        "description": "Formats SQL statements with clauses on their own lines, one select item per line, indented AND/OR conditions, subqueries and CREATE TABLE bodies, and keywords in the case you choose; comments are kept and formatting twice changes nothing. The linter flags UPDATE or DELETE without WHERE, SELECT * in views, comma joins without a condition, “= NULL”, NOT IN with a subquery, leading-wildcard LIKE, destructive statements and INSERT without a column list. It is the formatter of the Opsdeck Database desk.\n\nMethodology:\n- The SQL is split into tokens (keywords and names, quoted names, strings including E'…' and $tag$…$tag$, numbers, operators, comments) and into statements at semicolons outside parentheses and BEGIN … END blocks.\n- Each statement is written again from its tokens: main clauses (SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, RETURNING) start a line; select items get one line each; AND/OR of WHERE, ON and HAVING are indented (the AND of BETWEEN stays); subqueries and CREATE TABLE bodies are indented; function calls and IN lists stay inline. Since the layout depends only on the tokens, formatting the output again returns it unchanged.\n- The linter works on the same tokens per query level: missing WHERE in UPDATE/DELETE, * in the select list of a view, commas between tables in FROM (Cartesian product when there is no WHERE), = / <> NULL in conditions (but not in SET assignments), NOT IN (SELECT …), LIKE patterns that start with % or _, TRUNCATE/DROP/DROP COLUMN, and INSERT without a column list.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "opsdeck_sql_formatter",
        "x-owner-app": "opsdeck",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OpsdeckSqlFormatterInput"
              },
              "examples": {
                "example1": {
                  "summary": "Report query with joins, grouping and a date range",
                  "value": {}
                },
                "example2": {
                  "summary": "Lint: dangerous statements",
                  "value": {
                    "sql": "update accounts set balance = 0;\ndelete from sessions;\nselect * from orders, customers;\ncreate view open_orders as select * from orders where status = 'open';\nselect id from tickets where closed_at = null and owner not in (select id from users where active = false) and title like '%crash';",
                    "keywordCase": "upper",
                    "indent": 2
                  }
                },
                "example3": {
                  "summary": "Lower-case keywords, 4-space indent, a CTE and CASE",
                  "value": {
                    "sql": "WITH recent AS (SELECT id, total FROM orders WHERE placed_at > '2026-10-01') SELECT r.id, CASE WHEN r.total > 100 THEN 'big' ELSE 'small' END AS size FROM recent r ORDER BY r.id;",
                    "keywordCase": "lower",
                    "indent": 4
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpsdeckSqlFormatterResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "OpsdeckSqlFormatterInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "sql": {
            "title": "SQL",
            "type": "string",
            "maxLength": 100000,
            "default": "select c.name, count(*) as orders, sum(o.total) total from customers c join orders o on o.customer_id=c.id where o.placed_at between '2026-01-01' and '2026-06-30' and (c.country='DE' or c.country='AT') group by c.name having sum(o.total)>100 order by total desc limit 10;"
          },
          "keywordCase": {
            "title": "Keyword case",
            "type": "string",
            "enum": [
              "upper",
              "lower",
              "preserve"
            ],
            "default": "upper"
          },
          "indent": {
            "title": "Indent width",
            "type": "integer",
            "minimum": 1,
            "maximum": 8,
            "default": 2,
            "x-unit": "spaces"
          }
        },
        "required": []
      },
      "OpsdeckSqlFormatterResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "formatted",
              "statements",
              "issues",
              "changed"
            ],
            "properties": {
              "formatted": {
                "type": "string"
              },
              "statements": {
                "type": "number"
              },
              "changed": {
                "type": "boolean"
              },
              "issues": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "rule",
                    "level",
                    "statement",
                    "line",
                    "message"
                  ],
                  "properties": {
                    "rule": {
                      "type": "string"
                    },
                    "level": {
                      "enum": [
                        "error",
                        "warning",
                        "info"
                      ]
                    },
                    "statement": {
                      "type": "number"
                    },
                    "line": {
                      "type": "number"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}