{
  "openapi": "3.1.1",
  "info": {
    "title": "Codeharbor Format \u0026 Check API",
    "version": "1.0.0",
    "summary": "Format JSON, CSS and HTML and find syntax errors in JSON, YAML, JavaScript and TypeScript.",
    "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://codeharborformat.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Format JSON, CSS and HTML and find syntax errors in JSON, YAML, JavaScript and TypeScript.",
        "description": "Paste code to re-indent JSON, CSS or HTML and to list syntax problems with line and column: JSON is parsed strictly, YAML with a documented subset parser, JavaScript and TypeScript with Codeharbor’s own tokenizer. Nothing is run.\n\nMethodology:\n- JSON: a strict RFC 8259 parser reports the first error with line and column (trailing commas, single quotes, comments and unclosed strings get their own messages) and warns about duplicate keys. Formatting keeps the key order and the exact spelling of numbers; short arrays of numbers stay on one line.\n- YAML: a subset parser (block mappings and sequences, quoted and plain scalars, one-line flow collections, block scalars, comments, several documents) reports tabs in indentation, lines indented more or less than their siblings, missing colons, mixed lists and mappings, unclosed quotes and duplicate keys. Anchors and tags are accepted but not resolved.\n- JavaScript/TypeScript: Codeharbor’s tokenizer finds unterminated strings, template literals, comments and regular expressions, unmatched or mismatched brackets, reserved words used as names and a few statement mistakes. TypeScript is first reduced to JavaScript by blanking its types (positions kept); enums, namespaces, decorators and parameter properties are reported as unsupported. This is not a full parser or a type checker.\n- CSS formatting puts one declaration per line inside indented rule blocks; HTML formatting places block elements on their own lines and indents children while keeping inline content, \u003cpre\u003e and \u003ctextarea\u003e as they are.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "codeharbor_format",
        "x-owner-app": "codeharbor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeharborFormatInput"
              },
              "examples": {
                "example1": {
                  "summary": "Pretty-print minified JSON",
                  "value": {
                    "code": "{\"name\":\"harbour-api\",\"version\":\"1.4.0\",\"port\":8080,\"features\":{\"tides\":true,\"weather\":false},\"allowedOrigins\":[\"https://example.org\"]}",
                    "language": "json"
                  }
                },
                "example2": {
                  "summary": "Find the error in broken JSON",
                  "value": {
                    "code": "{\n  \"name\": \"harbour-api\",\n  \"port\": 8080,\n  \"features\": { \"tides\": true, },\n}",
                    "language": "json"
                  }
                },
                "example3": {
                  "summary": "Format minified CSS",
                  "value": {
                    "code": "body{margin:0;font:16px/1.5 system-ui}main{max-width:34rem;margin:2rem auto}button,input{padding:.5rem;border-radius:6px}",
                    "language": "css",
                    "indent": "4"
                  }
                },
                "example4": {
                  "summary": "Check YAML indentation",
                  "value": {
                    "code": "service: harbour-api\nreplicas: 2\nimage:\n  name: registry.example.org/harbour-api\n   tag: \"1.4.0\"\nenv:\n  - name: LOG_LEVEL\n    value: info\n",
                    "fileName": "deploy.yaml"
                  }
                },
                "example5": {
                  "summary": "Check a TypeScript function",
                  "value": {
                    "code": "interface Catch { boat: string; kilos: number }\nexport function total(list: Catch[]): number {\n  return list.reduce((sum, c) =\u003e sum + c.kilos, 0;\n}\n",
                    "language": "typescript"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CodeharborFormatResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "CodeharborFormatInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "title": "Code",
            "description": "Paste the file content.",
            "type": "string",
            "maxLength": 1000000,
            "default": ""
          },
          "language": {
            "title": "Language",
            "type": "string",
            "enum": [
              "auto",
              "json",
              "css",
              "html",
              "yaml",
              "javascript",
              "typescript",
              "markdown"
            ],
            "default": "auto"
          },
          "fileName": {
            "title": "File name (optional)",
            "description": "Used to pick the language when it is set to detect, e.g. config.yaml.",
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "indent": {
            "title": "Indentation",
            "type": "string",
            "enum": [
              "2",
              "4"
            ],
            "default": "2"
          }
        },
        "required": []
      },
      "CodeharborFormatResult": {
        "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"
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}