{
  "openapi": "3.0.0",
  "info": {
    "title": "LegalEasy API",
    "description": "API for analyzing legal documents and generating plain-English summaries with risk assessments",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://policycheck.tools"
    }
  ],
  "paths": {
    "/api/chatgpt/analyze": {
      "post": {
        "operationId": "analyzeLegalDocument",
        "summary": "Analyze a legal document",
        "description": "Analyzes legal text (terms of service, privacy policy, etc.) and returns a structured summary with risk assessment. Identifies key clauses like arbitration, liability caps, data sharing, and categorizes risks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text"],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "The full text of the legal document to analyze. Can be terms of service, privacy policy, refund policy, or any legal document."
                  },
                  "document_type": {
                    "type": "string",
                    "enum": ["terms", "privacy", "refund", "shipping", "other"],
                    "description": "Type of document being analyzed. Defaults to 'terms' if not specified.",
                    "default": "terms"
                  },
                  "product_name": {
                    "type": "string",
                    "description": "Optional: Name of the product/service (e.g., 'Zora', 'Shopify'). Helps with context."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully analyzed document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "summary": {
                      "type": "object",
                      "properties": {
                        "product": {
                          "type": "string",
                          "description": "Name of the product/service"
                        },
                        "updated_at": {
                          "type": "string",
                          "description": "When the terms were last updated (ISO date)"
                        },
                        "jurisdiction": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Governing jurisdiction(s)"
                        },
                        "sections": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "key": {
                                "type": "string",
                                "description": "Section identifier (e.g., 'disputes', 'liability', 'wallet')"
                              },
                              "title": {
                                "type": "string",
                                "description": "Human-readable section title"
                              },
                              "bullets": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                },
                                "description": "Key points in plain English"
                              },
                              "body": {
                                "type": "string",
                                "description": "Detailed explanation"
                              }
                            }
                          }
                        }
                      }
                    },
                    "risks": {
                      "type": "object",
                      "properties": {
                        "arbitration": {
                          "type": "boolean",
                          "description": "Whether binding arbitration is required"
                        },
                        "classActionWaiver": {
                          "type": "boolean",
                          "description": "Whether class action lawsuits are waived"
                        },
                        "liabilityCap": {
                          "type": "number",
                          "nullable": true,
                          "description": "Maximum liability amount in dollars"
                        },
                        "terminationAtWill": {
                          "type": "boolean",
                          "description": "Whether account can be terminated at any time"
                        },
                        "optOutDays": {
                          "type": "number",
                          "nullable": true,
                          "description": "Number of days to opt out of arbitration"
                        }
                      }
                    },
                    "key_findings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Most important findings in plain English"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/chatgpt/analyze-url": {
      "post": {
        "operationId": "analyzeLegalDocumentFromURL",
        "summary": "Analyze a legal document from a URL",
        "description": "Fetches and analyzes a legal document from a given URL. Automatically extracts the main content and provides a structured summary with risk assessment.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "URL of the legal document to analyze (e.g., 'https://example.com/terms', 'https://example.com/privacy')"
                  },
                  "document_type": {
                    "type": "string",
                    "enum": ["terms", "privacy", "refund", "shipping", "other"],
                    "description": "Type of document being analyzed. Auto-detected if not specified.",
                    "default": "terms"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully analyzed document from URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "The URL that was analyzed"
                    },
                    "title": {
                      "type": "string",
                      "description": "Page title"
                    },
                    "content_length": {
                      "type": "number",
                      "description": "Length of extracted content in characters"
                    },
                    "summary": {
                      "type": "object",
                      "description": "Same structure as /api/chatgpt/analyze response"
                    },
                    "risks": {
                      "type": "object",
                      "description": "Risk flags identified"
                    },
                    "key_findings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Most important findings"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
