{
  "openapi": "3.1.0",
  "info": {
    "title": "hanye Public API",
    "version": "1.0.0",
    "description": "hanye 群控监控台对外 REST（契约 1.0.0；宿主 6.8.1）。鉴权：Authorization: Bearer hy_… 或 X-API-Key。作用域 read ⊂ submit ⊂ control。响应信封：成功 { ok:true, data }，失败 { ok:false, error, error_code }。"
  },
  "servers": [
    {
      "url": "http://127.0.0.1:17890"
    }
  ],
  "tags": [
    {
      "name": "meta"
    },
    {
      "name": "printers"
    },
    {
      "name": "files"
    },
    {
      "name": "jobs"
    },
    {
      "name": "spools"
    },
    {
      "name": "scorecard"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API Key（hy_…），也可放在 X-API-Key"
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "ok",
          "error",
          "error_code"
        ],
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "type": "string"
          },
          "error_code": {
            "type": "string",
            "enum": [
              "UNAUTHENTICATED",
              "FORBIDDEN_SCOPE",
              "NOT_FOUND",
              "BAD_REQUEST",
              "RATE_LIMITED",
              "CONFLICT",
              "INTERNAL"
            ]
          }
        }
      },
      "Printer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "brand": {
            "type": "string"
          },
          "tech": {
            "type": "string"
          },
          "online": {
            "type": "boolean"
          },
          "busy": {
            "type": "boolean"
          },
          "state": {
            "type": "string"
          },
          "progress": {
            "type": [
              "number",
              "null"
            ]
          },
          "file": {
            "type": [
              "string",
              "null"
            ]
          },
          "temperatures": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/public/v1/openapi.json": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "OpenAPI 3.1 契约",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI document"
          }
        }
      }
    },
    "/api/public/v1/ping": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "连通性与作用域自检",
        "responses": {
          "200": {
            "description": "{ ok, data: { version, scope, contract } }"
          },
          "401": {
            "description": "UNAUTHENTICATED"
          }
        }
      }
    },
    "/api/public/v1/printers": {
      "get": {
        "tags": [
          "printers"
        ],
        "summary": "打印机列表（含实时状态）",
        "parameters": [
          {
            "name": "tech",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "fdm",
                "resin"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ ok, data: { printers: [...] } }"
          }
        }
      }
    },
    "/api/public/v1/printers/{id}": {
      "get": {
        "tags": [
          "printers"
        ],
        "summary": "单台打印机",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "printer"
          },
          "404": {
            "description": "NOT_FOUND"
          }
        }
      }
    },
    "/api/public/v1/printers/{id}/commands": {
      "post": {
        "tags": [
          "printers"
        ],
        "summary": "打印机控制（需 control）",
        "description": "command: pause|resume|cancel|emergency_stop|home|jog|set_temp|set_light|power。Tier C（cancel/emergency_stop/set_temp/jog/home/power）须 confirm:true。",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "command"
                ],
                "properties": {
                  "command": {
                    "type": "string"
                  },
                  "confirm": {
                    "type": "boolean"
                  },
                  "temperature": {
                    "type": "number"
                  },
                  "heater": {
                    "type": "string"
                  },
                  "axis": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "on": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ok"
          },
          "403": {
            "description": "FORBIDDEN_SCOPE"
          }
        }
      }
    },
    "/api/public/v1/files": {
      "get": {
        "tags": [
          "files"
        ],
        "summary": "文件库列表（read）",
        "responses": {
          "200": {
            "description": "{ files }"
          }
        }
      },
      "post": {
        "tags": [
          "files"
        ],
        "summary": "上传到文件库（submit）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filename",
                  "content_base64"
                ],
                "properties": {
                  "filename": {
                    "type": "string"
                  },
                  "content_base64": {
                    "type": "string"
                  },
                  "tech": {
                    "type": "string",
                    "enum": [
                      "fdm",
                      "resin",
                      "model"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "{ file }"
          }
        }
      }
    },
    "/api/public/v1/jobs": {
      "get": {
        "tags": [
          "jobs"
        ],
        "summary": "近期打印任务（来自打印记录）",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ jobs }"
          }
        }
      },
      "post": {
        "tags": [
          "jobs"
        ],
        "summary": "提交开打（submit；有 preferred_printer 时直控，否则记入打印申请队列）",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_id": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "preferred_printer": {
                    "type": "string"
                  },
                  "confirm": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "{ job_ids }"
          }
        }
      }
    },
    "/api/public/v1/jobs/{id}": {
      "get": {
        "tags": [
          "jobs"
        ],
        "summary": "单条打印记录",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "job"
          },
          "404": {
            "description": "NOT_FOUND"
          }
        }
      }
    },
    "/api/public/v1/spools": {
      "get": {
        "tags": [
          "spools"
        ],
        "summary": "耗材料卷列表",
        "responses": {
          "200": {
            "description": "{ spools }"
          }
        }
      }
    },
    "/api/public/v1/spools/{id}": {
      "get": {
        "tags": [
          "spools"
        ],
        "summary": "单卷耗材",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "spool"
          },
          "404": {
            "description": "NOT_FOUND"
          }
        }
      },
      "patch": {
        "tags": [
          "spools"
        ],
        "summary": "更新余量等（submit）",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "remaining_weight": {
                    "type": "number"
                  },
                  "name": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "spool"
          }
        }
      }
    },
    "/api/public/v1/scorecard": {
      "get": {
        "tags": [
          "scorecard"
        ],
        "summary": "农场稼动率摘要",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 7
            }
          }
        ],
        "responses": {
          "200": {
            "description": "summary"
          }
        }
      }
    }
  }
}