{
  "openapi": "3.0.3",
  "info": {
    "description": "独立测试工作台。匿名读取初始样例或单次计算可省略会话。写操作与保存外部运行记录必须带 X-WebGIS-Test-Session；会话失效返回 410，必填头缺失返回 428。",
    "title": "GIS 三维数据、点选识别与属性查询",
    "version": "2.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": {
      "get": {
        "summary": "按类别或编号/名称查对象",
        "operationId": "get_objects",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ObjectList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Local host / origin required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          }
        },
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/objects/{objectId}": {
      "get": {
        "summary": "查询对象及显示覆盖值",
        "operationId": "get_objects_objectId",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Local host / origin required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          }
        },
        "parameters": [
          {
            "name": "objectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "URL-encoded source elementId"
          }
        ]
      }
    },
    "/api/v1/models": {
      "get": {
        "summary": "3D 数据目录、原始模型 URL、坐标系与缺口",
        "operationId": "get_models",
        "responses": {
          "200": {
            "description": "可直接加载的离线模型",
            "content": {
              "application/json": {
                "example": {
                  "items": [
                    {
                      "id": "indoor-bim",
                      "url": "/models/indoor.glb",
                      "format": "glTF 2.0 binary (GLB)",
                      "units": "metres",
                      "up": "Y",
                      "objectIdField": "nodes[].extras.objectId",
                      "coordinateFrame": "demo_pointcloud_z_up_m",
                      "sourceToGltf": "(X,Y,Z) -> (X,Z,-Y)",
                      "gisTransform": null,
                      "sourceSha256": "a1ded499f38fd7dea160efa2b6e51046a875b9a2520baca90147693ee66ef857",
                      "sha256": "4a881f3502f83d6fe442dd1e88e710057dbae0c78c613f6d9f1ba750821d9952",
                      "objectCount": 328,
                      "renderableCount": 322,
                      "bytes": 13699756
                    }
                  ]
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "url": {
                            "type": "string"
                          },
                          "format": {
                            "type": "string"
                          },
                          "units": {
                            "type": "string"
                          },
                          "up": {
                            "type": "string"
                          },
                          "objectIdField": {
                            "type": "string"
                          },
                          "coordinateFrame": {
                            "type": "string"
                          },
                          "sourceToGltf": {
                            "type": "string"
                          },
                          "gisTransform": {
                            "type": "object",
                            "nullable": true
                          },
                          "sourceSha256": {
                            "type": "string"
                          },
                          "sha256": {
                            "type": "string"
                          },
                          "objectCount": {
                            "type": "integer"
                          },
                          "renderableCount": {
                            "type": "integer"
                          },
                          "bytes": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Local host / origin required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          }
        }
      }
    },
    "/models/indoor.glb": {
      "get": {
        "security": [],
        "summary": "下载 GLB 模型",
        "responses": {
          "200": {
            "description": "二进制 GLB",
            "content": {
              "model/gltf-binary": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/pick": {
      "post": {
        "operationId": "pickObject",
        "summary": "按点击射线识别最近的可见构件",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PickRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "最近几何命中，或 hit=false 且命中字段为 null",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PickResult"
                }
              }
            }
          },
          "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": "须使用 POST",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "模型版本不匹配",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "指定会话已失效"
          },
          "413": {
            "description": "超过 32 KiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "需要 application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "TestSession": {
        "type": "apiKey",
        "in": "header",
        "name": "X-WebGIS-Test-Session",
        "description": "POST /api/v1/test-sessions 后取得 sessionId。读写同一轮结果时带此头。仅持有者可操作；重启和结束操作后仍可重开。"
      }
    },
    "schemas": {
      "Object": {
        "type": "object",
        "required": [
          "objectId",
          "layerId",
          "display",
          "simulated",
          "capabilities"
        ],
        "properties": {
          "objectId": {
            "type": "string",
            "description": "完整业务编号，与 GLB 节点 extras.objectId 对应；来源编号另见 sourceElementId"
          },
          "layerId": {
            "type": "string",
            "enum": [
              "indoor-bim"
            ]
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "subtype": {
            "type": "string"
          },
          "sourceElementId": {
            "type": "string"
          },
          "semanticStatus": {
            "type": "string"
          },
          "basis": {
            "type": "string"
          },
          "coordinateFrame": {
            "type": "string"
          },
          "sourceBounds": {
            "type": "object",
            "nullable": true
          },
          "sourceCenter": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "nullable": true
          },
          "renderable": {
            "type": "boolean"
          },
          "capabilities": {
            "type": "object",
            "properties": {
              "move": {
                "type": "boolean"
              },
              "color": {
                "type": "boolean"
              },
              "states": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "display": {
            "type": "object",
            "properties": {
              "translation": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "state": {
                "type": "string",
                "nullable": true
              },
              "color": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "observationState": {
            "type": "string",
            "nullable": true,
            "description": "Always null in this isolated display prototype"
          },
          "simulated": {
            "type": "boolean",
            "enum": [
              true
            ]
          }
        }
      },
      "ObjectList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Object"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "PickRequest": {
        "type": "object",
        "required": [
          "modelId",
          "origin",
          "direction"
        ],
        "properties": {
          "modelId": {
            "type": "string",
            "example": "indoor-bim"
          },
          "modelSha256": {
            "type": "string",
            "description": "可选，和已加载 GLB 的版本核对"
          },
          "origin": {
            "type": "array",
            "minItems": 3,
            "maxItems": 3,
            "items": {
              "type": "number"
            },
            "description": "同版本 GLB 的局部 Y 向上坐标，米"
          },
          "direction": {
            "type": "array",
            "minItems": 3,
            "maxItems": 3,
            "items": {
              "type": "number"
            },
            "description": "相同坐标系，非零，服务端归一化"
          },
          "scope": {
            "oneOf": [
              {
                "type": "string",
                "enum": [
                  "all",
                  "pantry-windows"
                ]
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "缺省全模型；仅在画面隐藏构件时指定可见范围"
          },
          "near": {
            "type": "number",
            "minimum": 0
          },
          "far": {
            "type": "number",
            "minimum": 0
          }
        }
      },
      "PickResult": {
        "type": "object",
        "required": [
          "modelId",
          "hit",
          "objectId",
          "point",
          "distance"
        ],
        "properties": {
          "modelId": {
            "type": "string"
          },
          "hit": {
            "type": "boolean"
          },
          "objectId": {
            "type": "string",
            "nullable": true
          },
          "point": {
            "type": "array",
            "minItems": 3,
            "maxItems": 3,
            "items": {
              "type": "number"
            },
            "nullable": true
          },
          "distance": {
            "type": "number",
            "nullable": true,
            "description": "距射线起点的米数"
          }
        }
      }
    }
  }
}