{
  "openapi": "3.0.3",
  "info": {
    "title": "P2 Tasks 教学契约",
    "version": "1.0.0",
    "description": "手写静态契约，示例未执行。无认证，仅限本机教学。"
  },
  "paths": {
    "/api/tasks": {
      "get": {
        "operationId": "listTasks",
        "responses": {
          "200": {
            "description": "按id升序前100项",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "maxItems": 100,
                  "items": {
                    "$ref": "#/components/schemas/Task"
                  }
                }
              }
            }
          },
          "500": {
            "description": "未预期错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createTask",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Create"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "新任务",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "400": {
            "description": "输入无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "未预期错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/tasks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,18}$",
            "description": "正十进制Long字符串；上限9223372036854775807，超出为400"
          }
        }
      ],
      "get": {
        "operationId": "getTask",
        "responses": {
          "200": {
            "description": "当前任务",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "400": {
            "description": "输入无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "任务不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "未预期错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "replaceTask",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Update"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "更新后的版本",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "400": {
            "description": "输入无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "任务不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "版本已变化，请重新读取",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "未预期错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteTask",
        "parameters": [
          {
            "name": "version",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(0|[1-9][0-9]{0,18})$",
              "description": "非负Long字符串；上限9223372036854775807"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "已删除"
          },
          "400": {
            "description": "输入无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "任务不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "版本已变化，请重新读取",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "未预期错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Task": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "done",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,18}$",
            "description": "正十进制Long字符串；上限9223372036854775807，超出为400"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "不得全空白；按Java UTF-16长度至多120，提交时strip"
          },
          "done": {
            "type": "boolean"
          },
          "version": {
            "type": "string",
            "pattern": "^(0|[1-9][0-9]{0,18})$",
            "description": "非负Long字符串；上限9223372036854775807"
          }
        }
      },
      "Create": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "done"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "不得全空白；按Java UTF-16长度至多120，提交时strip"
          },
          "done": {
            "type": "boolean"
          }
        }
      },
      "Update": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "done",
          "version"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "不得全空白；按Java UTF-16长度至多120，提交时strip"
          },
          "done": {
            "type": "boolean"
          },
          "version": {
            "type": "string",
            "pattern": "^(0|[1-9][0-9]{0,18})$",
            "description": "非负Long字符串；上限9223372036854775807"
          }
        }
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
