{
  "openapi": "3.1.0",
  "info": {
    "title": "jsonnorm Public API",
    "version": "1.0.0",
    "description": "Deterministic JSON and NDJSON to CSV conversion API."
  },
  "servers": [{ "url": "https://jsonnorm.com" }],
  "paths": {
    "/api/v1/convert": {
      "post": {
        "summary": "Convert JSON or NDJSON to CSV anonymously",
        "parameters": [{
          "name": "response",
          "in": "query",
          "required": false,
          "schema": { "type": "string", "enum": ["csv", "metadata"], "default": "csv" }
        }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": {} },
            "application/x-ndjson": { "schema": { "type": "string" } },
            "multipart/form-data": {
              "description": "Send exactly one JSON file in the file field. Other multipart fields are rejected.",
              "schema": {
                "type": "object",
                "required": ["file"],
                "additionalProperties": false,
                "properties": { "file": { "type": "string", "format": "binary" } }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "CSV download or metadata JSON.",
            "content": {
              "text/csv": { "schema": { "type": "string", "format": "binary" } },
              "application/json": { "$ref": "#/components/schemas/ConversionMetadata" }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "408": { "$ref": "#/components/responses/DeadlineExceeded" },
          "413": { "$ref": "#/components/responses/TooLarge" },
          "415": { "$ref": "#/components/responses/UnsupportedMediaType" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "summary": "Anonymous API readiness",
        "responses": {
          "200": { "description": "The API is ready to accept bounded conversions." },
          "503": { "description": "The API is temporarily unavailable because capacity protections are active." }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ConversionMetadata": {
        "type": "object",
        "required": ["rows", "columns", "truncated", "inputBytes", "outputBytes"],
        "properties": {
          "rows": { "type": "integer", "format": "int64" },
          "columns": { "type": "integer", "format": "int64" },
          "truncated": { "type": "boolean" },
          "inputBytes": { "type": "integer", "format": "int64" },
          "outputBytes": { "type": "integer", "format": "int64" }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": ["error", "warning"],
        "properties": {
          "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" }, "reason": { "type": "string", "description": "Optional stable detail reason for a specific validation failure." } } },
          "warning": { "type": "object", "properties": { "kind": { "type": "string" }, "message": { "type": "string" } } }
        }
      }
    },
    "responses": {
      "BadRequest": { "description": "Invalid input or conversion plan. Codes: JSON_PARSE_ERROR, TOKEN_TOO_LARGE, KEY_TOO_LARGE, DEPTH_LIMIT_EXCEEDED, COLUMN_LIMIT_EXCEEDED, ROW_LIMIT_EXCEEDED, GENERATED_CELL_LIMIT_EXCEEDED, PLAN_VALIDATION_ERROR, INVALID_INPUT.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "DeadlineExceeded": { "description": "The bounded conversion deadline elapsed. Code: DEADLINE_EXCEEDED.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "TooLarge": { "description": "The input or generated CSV exceeds a bounded size. Codes: INPUT_TOO_LARGE, OUTPUT_LIMIT_EXCEEDED.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "UnsupportedMediaType": { "description": "The request Content-Type is not documented. Code: UNSUPPORTED_MEDIA_TYPE.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "RateLimited": { "description": "An anonymous fair-use or concurrency safeguard asked the client to wait. Codes: RATE_LIMITED, CONCURRENCY_LIMIT_EXCEEDED.", "headers": { "Retry-After": { "schema": { "type": "integer" }, "description": "Minimum seconds to wait before retrying." } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "InternalError": { "description": "An unexpected failure occurred. Code: INTERNAL_ERROR.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } },
      "ServiceUnavailable": { "description": "The service is temporarily busy. Retry the request after the delay in Retry-After. Code: SERVICE_UNAVAILABLE.", "headers": { "Retry-After": { "schema": { "type": "integer" }, "description": "Minimum seconds before retrying the request." } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEnvelope" } } } }
    }
  }
}
