{
  "openapi": "3.1.0",
  "info": {
    "title": "Metroidvania Studio local API",
    "version": "1.3.2",
    "description": "Local HTTP interface for the running editor. Use the loopback URL printed by its launcher. API version 1 and map format 2 remain stable."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/api/v1/capabilities": {
      "get": {
        "summary": "Editing schemas and execution limits",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        }
      }
    },
    "/api/v1/document": {
      "get": {
        "summary": "Current document and revision",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "instanceId": {
                      "type": "string"
                    },
                    "documentRevision": {
                      "type": "integer"
                    },
                    "document": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        }
      }
    },
    "/api/v1/jobs": {
      "post": {
        "summary": "Submit a Lua or operation batch job",
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "phase": {
                      "enum": [
                        "running",
                        "completed",
                        "conflict",
                        "cancelled",
                        "failed"
                      ]
                    },
                    "dryRun": {
                      "type": "boolean"
                    },
                    "operationCount": {
                      "type": "integer"
                    },
                    "changed": {
                      "type": "boolean"
                    },
                    "logs": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "error": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "errorCode": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "baseDocumentRevision": {
                      "type": "integer",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "clientId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "commandId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "expectedInstanceId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "lua",
                      "batch"
                    ]
                  },
                  "expectedDocumentRevision": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false
                  },
                  "seed": {
                    "type": "integer",
                    "format": "int32",
                    "default": 1
                  },
                  "source": {
                    "type": "string",
                    "description": "Lua source, at most 65536 UTF-8 bytes."
                  },
                  "batch": {
                    "$ref": "api--automation.schema.json"
                  }
                },
                "required": [
                  "kind",
                  "clientId",
                  "commandId",
                  "expectedInstanceId",
                  "expectedDocumentRevision"
                ],
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "kind": {
                          "const": "lua"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "source"
                      ]
                    },
                    "else": {
                      "required": [
                        "batch"
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs/lookup": {
      "get": {
        "summary": "Find a retained job by submission identity",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "phase": {
                      "enum": [
                        "running",
                        "completed",
                        "conflict",
                        "cancelled",
                        "failed"
                      ]
                    },
                    "dryRun": {
                      "type": "boolean"
                    },
                    "operationCount": {
                      "type": "integer"
                    },
                    "changed": {
                      "type": "boolean"
                    },
                    "logs": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "error": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "errorCode": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "baseDocumentRevision": {
                      "type": "integer",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          },
          "404": {
            "description": "No retained submission"
          }
        },
        "parameters": [
          {
            "name": "clientId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "commandId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/jobs/{id}": {
      "get": {
        "summary": "Read job status",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "phase": {
                      "enum": [
                        "running",
                        "completed",
                        "conflict",
                        "cancelled",
                        "failed"
                      ]
                    },
                    "dryRun": {
                      "type": "boolean"
                    },
                    "operationCount": {
                      "type": "integer"
                    },
                    "changed": {
                      "type": "boolean"
                    },
                    "logs": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "error": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "errorCode": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "baseDocumentRevision": {
                      "type": "integer",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/jobs/{id}/cancel": {
      "post": {
        "summary": "Cancel an owned job",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "phase": {
                      "enum": [
                        "running",
                        "completed",
                        "conflict",
                        "cancelled",
                        "failed"
                      ]
                    },
                    "dryRun": {
                      "type": "boolean"
                    },
                    "operationCount": {
                      "type": "integer"
                    },
                    "changed": {
                      "type": "boolean"
                    },
                    "logs": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "error": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "errorCode": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "baseDocumentRevision": {
                      "type": "integer",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "clientId": {
                    "type": "string"
                  }
                },
                "required": [
                  "clientId"
                ]
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/scripts": {
      "get": {
        "summary": "List saved scripts and bundled examples",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "readOnly": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "readOnly"
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        }
      },
      "post": {
        "summary": "Save a workspace script without executing it",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "string"
                    },
                    "readOnly": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "source",
                    "revision",
                    "readOnly"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "A simple .lua filename."
                  },
                  "source": {
                    "type": "string",
                    "description": "1\u201365536 UTF-8 bytes."
                  },
                  "expectedRevision": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "null for a new file, otherwise the revision returned when opening the file."
                  }
                },
                "required": [
                  "name",
                  "source",
                  "expectedRevision"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/scripts/source": {
      "get": {
        "summary": "Read a saved script or example",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "string"
                    },
                    "readOnly": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "source",
                    "revision",
                    "readOnly"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or missing item"
          },
          "403": {
            "description": "Host or Origin rejected"
          },
          "409": {
            "description": "Revision, identity or capacity conflict"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    }
  }
}
