{
  "openapi": "3.1.0",
  "info": {
    "title": "Dynasty House API",
    "version": "1.0.0",
    "description": "Read and write a user's family tree. Designed for AI agents: the agent does the genealogy research, Dynasty House is the beautiful, private, permanent home for the results. Create a key at https://dynasty.house/app/settings (paid plans).",
    "contact": {
      "email": "hello@dynasty.house",
      "url": "https://dynasty.house/developers"
    }
  },
  "servers": [
    {
      "url": "https://dynasty.house/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "dyn_live_*",
        "description": "Personal API key as a Bearer token."
      }
    },
    "schemas": {
      "Person": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "given": {
            "type": [
              "string",
              "null"
            ]
          },
          "surname": {
            "type": [
              "string",
              "null"
            ]
          },
          "maiden_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "sex": {
            "type": "string",
            "enum": [
              "M",
              "F",
              "U"
            ]
          },
          "birth_date": {
            "type": [
              "string",
              "null"
            ],
            "description": "Free text, e.g. \"1888\", \"12 May 1888\", \"abt 1890\"."
          },
          "birth_place": {
            "type": [
              "string",
              "null"
            ]
          },
          "death_date": {
            "type": [
              "string",
              "null"
            ]
          },
          "death_place": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ],
            "description": "Research notes. Always cite your source here."
          },
          "biography": {
            "type": [
              "string",
              "null"
            ]
          },
          "distinction": {
            "type": [
              "string",
              "null"
            ],
            "description": "One-line claim to fame (max 140 chars)."
          },
          "public_opt_out": {
            "type": "boolean"
          },
          "has_photo": {
            "type": "boolean"
          }
        }
      },
      "Union": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "partner1_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "partner2_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "marriage_date": {
            "type": [
              "string",
              "null"
            ]
          },
          "marriage_place": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ChildLink": {
        "type": "object",
        "properties": {
          "union_id": {
            "type": "string"
          },
          "child_id": {
            "type": "string"
          }
        }
      },
      "NewPerson": {
        "type": "object",
        "properties": {
          "given": {
            "type": "string"
          },
          "surname": {
            "type": "string"
          },
          "maiden_name": {
            "type": "string"
          },
          "sex": {
            "type": "string",
            "enum": [
              "M",
              "F",
              "U"
            ]
          },
          "birth_date": {
            "type": "string"
          },
          "birth_place": {
            "type": "string"
          },
          "death_date": {
            "type": "string"
          },
          "death_place": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "link": {
            "type": "object",
            "description": "Tie the new person to an existing one. type is the NEW person's relationship to personId.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "spouse",
                  "child",
                  "parent"
                ]
              },
              "personId": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "personId"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/me": {
      "get": {
        "summary": "The account this API key belongs to",
        "operationId": "getMe",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string"
                    },
                    "name": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "plan": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/trees": {
      "get": {
        "summary": "List trees you own or can access",
        "operationId": "listTrees",
        "responses": {
          "200": {
            "description": "Trees",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trees": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new tree",
        "operationId": "createTree",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created tree"
          }
        }
      }
    },
    "/trees/{id}": {
      "get": {
        "summary": "Get the whole family graph (people, unions, children) in one call",
        "operationId": "getTree",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The graph",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tree": {
                      "type": "object"
                    },
                    "people": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Person"
                      }
                    },
                    "unions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Union"
                      }
                    },
                    "children": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChildLink"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/trees/{id}/people": {
      "post": {
        "summary": "Add a person, optionally linked to an existing one",
        "operationId": "addPerson",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewPerson"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/people/{id}": {
      "get": {
        "summary": "Get one person's full record",
        "operationId": "getPerson",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Person",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Person"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "patch": {
        "summary": "Partial update — send only the fields to change",
        "operationId": "updatePerson",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Person"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      },
      "delete": {
        "summary": "Remove a person and tidy any orphaned partnerships",
        "operationId": "deletePerson",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    }
  }
}