{
  "openapi": "3.0.3",
  "info": {
    "description": "固定 indoor-bim 模型。offsetM 为相对 GLB 原位的累计位移，deltaM 为本次增量，顺序 X、Y、Z，单位米。",
    "title": "BIM / GIS 构件移动、状态与颜色",
    "version": "1.1.0"
  },
  "servers": [
    {
      "url": "https://workbench-test.scri-digital-twin-cctv.com"
    }
  ],
  "security": [
    {},
    {
      "TestSession": []
    }
  ],
  "paths": {
    "/api/v1/test-sessions/history": {
      "get": {
        "summary": "读取本轮历史，最新在前，每页最多 50 条",
        "security": [
          {
            "TestSession": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "before",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "records 数组，每条含 sequence、method、path、time、status、请求和响应"
          }
        }
      }
    },
    "/api/v1/test-sessions": {
      "post": {
        "operationId": "createTestSession",
        "summary": "开始一次独立测试（无请求体）",
        "security": [],
        "responses": {
          "201": {
            "description": "新会话",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sessionId",
                    "idleTimeoutSeconds"
                  ],
                  "properties": {
                    "sessionId": {
                      "type": "string",
                      "description": "测试历史访问凭证，持有者可继续读写本轮。"
                    },
                    "persistent": {
                      "type": "boolean",
                      "example": true
                    },
                    "idleTimeoutSeconds": {
                      "type": "integer",
                      "nullable": true,
                      "example": null
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "当前并行会话已满"
          }
        }
      }
    },
    "/api/v1/test-sessions/current": {
      "get": {
        "operationId": "getTestSession",
        "summary": "读取当前测试历史身份",
        "security": [
          {
            "TestSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "会话有效",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sessionId",
                    "idleTimeoutSeconds"
                  ],
                  "properties": {
                    "sessionId": {
                      "type": "string",
                      "description": "测试历史访问凭证，持有者可继续读写本轮。"
                    },
                    "persistent": {
                      "type": "boolean",
                      "example": true
                    },
                    "idleTimeoutSeconds": {
                      "type": "integer",
                      "nullable": true,
                      "example": null
                    }
                  }
                }
              }
            }
          },
          "410": {
            "description": "会话已失效"
          },
          "428": {
            "description": "缺少会话请求头"
          }
        }
      },
      "delete": {
        "operationId": "endTestSession",
        "summary": "确认本轮测试已保存",
        "security": [
          {
            "TestSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "已结束",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "closed"
                  ],
                  "properties": {
                    "closed": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "410": {
            "description": "会话已失效"
          },
          "428": {
            "description": "缺少会话请求头"
          }
        }
      }
    },
    "/api/v1/objects/{objectId}/move": {
      "parameters": [
        {
          "in": "path",
          "name": "objectId",
          "required": true,
          "schema": {
            "type": "string"
          },
          "example": "250e5960-b361-412e-bc05-40ec2c494126:W01"
        }
      ],
      "post": {
        "security": [
          {
            "TestSession": []
          }
        ],
        "operationId": "moveObject",
        "summary": "对指定构件应用一次相对位移",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "expectedRevision",
                  "deltaM"
                ],
                "properties": {
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "deltaM": {
                    "allOf": [
                      {
                        "$ref": "#/components/schemas/Vector"
                      }
                    ],
                    "description": "至少一轴非零"
                  }
                }
              },
              "example": {
                "expectedRevision": 0,
                "deltaM": [
                  0,
                  0.5,
                  0
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "位移已提交",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "modelId",
                    "objectId",
                    "frame",
                    "before",
                    "after",
                    "deltaM"
                  ],
                  "properties": {
                    "modelId": {
                      "type": "string"
                    },
                    "objectId": {
                      "type": "string"
                    },
                    "frame": {
                      "type": "string",
                      "enum": [
                        "gltf-local-y-up"
                      ]
                    },
                    "before": {
                      "$ref": "#/components/schemas/Position"
                    },
                    "after": {
                      "$ref": "#/components/schemas/Position"
                    },
                    "deltaM": {
                      "$ref": "#/components/schemas/Vector"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "来源或权限受限",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "方法错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "版本冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "413": {
            "description": "请求过大",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "需要 JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "对象无几何或位移越界",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "此操作或运行记录缺少会话请求头"
          }
        }
      }
    },
    "/api/v1/objects/{objectId}/position": {
      "parameters": [
        {
          "in": "path",
          "name": "objectId",
          "required": true,
          "schema": {
            "type": "string"
          },
          "example": "250e5960-b361-412e-bc05-40ec2c494126:W01"
        }
      ],
      "get": {
        "operationId": "getPosition",
        "summary": "读取最新累计偏移和版本",
        "responses": {
          "200": {
            "description": "当前位置",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Position"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "422": {
            "description": "对象无几何或位移越界",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/scene": {
      "get": {
        "summary": "读取模型、能力和位置／状态／颜色快照",
        "responses": {
          "200": {
            "description": "未列入 positions 的构件初始偏移和版本均为零",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "model": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "url": {
                          "type": "string"
                        },
                        "sha256": {
                          "type": "string"
                        }
                      }
                    },
                    "objects": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "objectId": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "category": {
                            "type": "string"
                          },
                          "subtype": {
                            "type": "string"
                          },
                          "capabilities": {
                            "type": "object",
                            "properties": {
                              "states": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              "move": {
                                "type": "boolean"
                              },
                              "color": {
                                "type": "boolean"
                              }
                            }
                          }
                        }
                      }
                    },
                    "positions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Position"
                      }
                    },
                    "appearances": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "allOf": [
                              {
                                "$ref": "#/components/schemas/State"
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "property": {
                                    "type": "string",
                                    "enum": [
                                      "state"
                                    ]
                                  }
                                },
                                "required": [
                                  "property"
                                ]
                              }
                            ]
                          },
                          {
                            "allOf": [
                              {
                                "$ref": "#/components/schemas/Color"
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "property": {
                                    "type": "string",
                                    "enum": [
                                      "color"
                                    ]
                                  }
                                },
                                "required": [
                                  "property"
                                ]
                              }
                            ]
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          }
        }
      }
    },
    "/api/v1/objects/{objectId}/state": {
      "parameters": [
        {
          "in": "path",
          "name": "objectId",
          "required": true,
          "schema": {
            "type": "string"
          },
          "example": "250e5960-b361-412e-bc05-40ec2c494126:W01"
        }
      ],
      "get": {
        "operationId": "readState",
        "summary": "读取门窗状态与独立版本",
        "responses": {
          "200": {
            "description": "门窗状态",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/State"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "422": {
            "description": "构件不支持属性、缺少几何或状态无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "security": [
          {
            "TestSession": []
          }
        ],
        "operationId": "setState",
        "summary": "保存门窗状态",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "expectedRevision",
                  "state"
                ],
                "properties": {
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "open",
                      "closed"
                    ]
                  }
                }
              },
              "example": {
                "expectedRevision": 0,
                "state": "open"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已保存，同值无变更时版本保持原值",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "modelId",
                    "objectId",
                    "before",
                    "after"
                  ],
                  "properties": {
                    "modelId": {
                      "type": "string"
                    },
                    "objectId": {
                      "type": "string"
                    },
                    "before": {
                      "$ref": "#/components/schemas/State"
                    },
                    "after": {
                      "$ref": "#/components/schemas/State"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "来源或权限受限",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "方法错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "版本冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "413": {
            "description": "请求过大",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "需要 JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "构件不支持属性、缺少几何或状态无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "此操作或运行记录缺少会话请求头"
          }
        }
      }
    },
    "/api/v1/objects/{objectId}/color": {
      "parameters": [
        {
          "in": "path",
          "name": "objectId",
          "required": true,
          "schema": {
            "type": "string"
          },
          "example": "250e5960-b361-412e-bc05-40ec2c494126:W01"
        }
      ],
      "get": {
        "operationId": "readColor",
        "summary": "读取颜色覆盖与独立版本",
        "responses": {
          "200": {
            "description": "颜色覆盖",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Color"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "422": {
            "description": "构件不支持属性、缺少几何或状态无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "security": [
          {
            "TestSession": []
          }
        ],
        "operationId": "setColor",
        "summary": "保存颜色覆盖",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "expectedRevision",
                  "color"
                ],
                "properties": {
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "color": {
                    "type": "string",
                    "pattern": "^#[0-9a-fA-F]{6}$",
                    "nullable": true
                  }
                }
              },
              "example": {
                "expectedRevision": 0,
                "color": "#287DCE"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已保存，同值无变更时版本保持原值",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "modelId",
                    "objectId",
                    "before",
                    "after"
                  ],
                  "properties": {
                    "modelId": {
                      "type": "string"
                    },
                    "objectId": {
                      "type": "string"
                    },
                    "before": {
                      "$ref": "#/components/schemas/Color"
                    },
                    "after": {
                      "$ref": "#/components/schemas/Color"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "来源或权限受限",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "编号不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "方法错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "版本冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "413": {
            "description": "请求过大",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "需要 JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "构件不支持属性、缺少几何或状态无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "此操作或运行记录缺少会话请求头"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "TestSession": {
        "type": "apiKey",
        "in": "header",
        "name": "X-WebGIS-Test-Session",
        "description": "POST /api/v1/test-sessions 后取得 sessionId。读写同一轮结果时带此头。仅持有者可操作；重启和结束操作后仍可重开。"
      }
    },
    "schemas": {
      "Position": {
        "type": "object",
        "required": [
          "objectId",
          "offsetM",
          "revision"
        ],
        "properties": {
          "objectId": {
            "type": "string"
          },
          "offsetM": {
            "$ref": "#/components/schemas/Vector"
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "Vector": {
        "type": "array",
        "minItems": 3,
        "maxItems": 3,
        "items": {
          "type": "number",
          "minimum": -100,
          "maximum": 100,
          "multipleOf": 0.001
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "State": {
        "type": "object",
        "required": [
          "objectId",
          "state",
          "revision"
        ],
        "properties": {
          "objectId": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "Color": {
        "type": "object",
        "required": [
          "objectId",
          "color",
          "revision"
        ],
        "properties": {
          "objectId": {
            "type": "string"
          },
          "color": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "nullable": true
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    }
  }
}