{
  "openapi": "3.1.1",
  "info": {
    "title": "Regex Golf Arena API",
    "version": "1.0.0",
    "summary": "Match the left list, avoid the right list — in as few characters as possible.",
    "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://regexgolfarena.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Match the left list, avoid the right list — in as few characters as possible.",
        "description": "Regex golf with built-in puzzles: write one JavaScript regular expression that matches every string on the “match” list and none on the “don’t match” list. Shorter is better; perfect solutions can join a per-puzzle top-20 leaderboard. Use “dry run” to test without submitting.\n\nMethodology:\n- Your pattern is compiled with JavaScript’s RegExp (flags i/u optional) and tested against every string with RegExp.test, so it may match anywhere in the string unless you anchor it.\n- Score = 10 × (strings on the match list that match + strings on the don’t-match list that do not match) − regex length, as in classic regex golf. A solution is perfect when every string is classified correctly.\n- Safety: patterns are limited to 200 characters, control characters are refused, and patterns where an unbounded quantifier repeats a group that contains another variable quantifier or an alternation — the classic catastrophic-backtracking shapes such as (a+)+ or (a|aa)* — are rejected before running. The puzzle strings are short (at most 12 characters), which bounds the remaining work.\n- Leaderboard: only perfect, non-dry-run solutions are entered, ranked by length, then date. Each puzzle keeps the top 20; an identical regex only counts once, and each nickname keeps its best entry. Only nickname, length, score and date are shown — never the regex — so nobody gets spoilers.",
        "tags": [
          "fun"
        ],
        "x-mcp-tool": "regex_golf_arena",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegexGolfArenaInput"
              },
              "examples": {
                "example1": {
                  "summary": "Warm-up, dry run",
                  "value": {
                    "puzzle": "warm-up",
                    "regex": "cat",
                    "flags": "none",
                    "dryRun": true
                  }
                },
                "example2": {
                  "summary": "Seeing double, almost right",
                  "value": {
                    "puzzle": "doubles",
                    "regex": "(ll|ff|tt|mm|pp|rr)",
                    "flags": "none",
                    "dryRun": true
                  }
                },
                "example3": {
                  "summary": "Show the ABBA puzzle",
                  "value": {
                    "puzzle": "abba",
                    "dryRun": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegexGolfArenaResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "RegexGolfArenaInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "puzzle": {
            "title": "Puzzle",
            "type": "string",
            "enum": [
              "warm-up",
              "ending",
              "hex-colours",
              "doubles",
              "abba",
              "iso-dates",
              "powers-of-two",
              "vowel-parade"
            ],
            "default": "warm-up"
          },
          "regex": {
            "title": "Your regex",
            "description": "Without slashes. Tested with JavaScript RegExp.test (a match anywhere counts unless you anchor with ^ and $). Leave empty to see the puzzle and its leaderboard.",
            "type": "string",
            "maxLength": 200
          },
          "flags": {
            "title": "Flags",
            "description": "Flags do not count towards the length.",
            "type": "string",
            "enum": [
              "none",
              "i",
              "u",
              "iu"
            ],
            "default": "none"
          },
          "nickname": {
            "title": "Nickname for the leaderboard (optional)",
            "description": "Letters, digits, spaces, dot, dash and underscore; up to 24 characters. Shown publicly with the length and date — the regex itself is never shown.",
            "type": "string",
            "maxLength": 24
          },
          "dryRun": {
            "title": "Dry run (test only, do not submit to the leaderboard)",
            "type": "boolean",
            "default": false
          }
        },
        "required": []
      },
      "RegexGolfArenaResult": {
        "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": [
              "puzzle",
              "title",
              "hint",
              "match",
              "dontMatch",
              "par",
              "submission",
              "leaderboard"
            ],
            "properties": {
              "puzzle": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "match": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "dontMatch": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "par": {
                "type": "integer",
                "description": "Length of a known (not necessarily shortest) solution."
              },
              "submission": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "regex",
                  "flags",
                  "length",
                  "perfect",
                  "score",
                  "matched",
                  "missed",
                  "rejected",
                  "falsePositives",
                  "dryRun",
                  "leaderboardRank",
                  "leaderboardNote"
                ],
                "properties": {
                  "regex": {
                    "type": "string"
                  },
                  "flags": {
                    "type": "string"
                  },
                  "length": {
                    "type": "integer"
                  },
                  "perfect": {
                    "type": "boolean"
                  },
                  "score": {
                    "type": "integer",
                    "description": "10 × (correct matches + correct rejections) − length."
                  },
                  "matched": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "missed": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "rejected": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "falsePositives": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "dryRun": {
                    "type": "boolean"
                  },
                  "leaderboardRank": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "leaderboardNote": {
                    "type": "string"
                  }
                }
              },
              "leaderboard": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "rank",
                    "nickname",
                    "length",
                    "score",
                    "date"
                  ],
                  "properties": {
                    "rank": {
                      "type": "integer"
                    },
                    "nickname": {
                      "type": "string"
                    },
                    "length": {
                      "type": "integer"
                    },
                    "score": {
                      "type": "integer"
                    },
                    "date": {
                      "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"
              }
            }
          }
        }
      }
    }
  }
}