{
  "openapi": "3.1.0",
  "info": {
    "title": "LEGALDIGM for Microsoft 365 Copilot",
    "description": "Legaldigms rättsdatabas som API: svensk och europeisk lagtext per paragraf, domstolsavgöranden, internationella avgöranden och juridiska AI-svar med källhänvisning. Varje anrop kräver en API-nyckel och dras från kontots förbetalda tokensaldo. Skapa nyckel och köp tokenpaket på https://legaldigm.se/api-nycklar.",
    "version": "1.0.0",
    "contact": {
      "name": "Legaldigm",
      "url": "https://legaldigm.se/kontakt"
    },
    "termsOfService": "https://legaldigm.se/villkor"
  },
  "servers": [
    {
      "url": "https://zdpjpohbmxiaykcdswsb.supabase.co/functions/v1/legal-api",
      "description": "Legaldigm produktion"
    }
  ],
  "security": [
    {
      "OAuth2": [
        "openid",
        "email",
        "profile"
      ]
    }
  ],
  "paths": {
    "/v1/search": {
      "post": {
        "operationId": "searchLegalSources",
        "summary": "Sök i Legaldigms rättskällor",
        "description": "Söker i svensk lagtext per paragraf, svenska domstolsavgöranden och internationella avgöranden. Returnerar utdrag med källhänvisning som kan citeras.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Juridisk fråga eller sökord, t.ex. 'uppsägning personliga skäl'."
                  },
                  "limit": {
                    "type": "integer",
                    "description": "Antal träffar per källtyp. Standard 8.",
                    "default": 8
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Träffar med källhänvisning",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tool": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "tokens_billed": {
                      "type": "integer"
                    },
                    "balance": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/LegalSource"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        },
        "security": [
          {
            "OAuth2": [
              "openid",
              "email",
              "profile"
            ]
          }
        ]
      }
    },
    "/v1/law": {
      "post": {
        "operationId": "getLawSection",
        "summary": "Hämta ordagrann svensk lagtext",
        "description": "Hämtar författningstext för ett SFS-nummer, valfritt begränsat till en enskild paragraf.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sfs_number"
                ],
                "properties": {
                  "sfs_number": {
                    "type": "string",
                    "description": "SFS-nummer, t.ex. '1982:80'."
                  },
                  "section_number": {
                    "type": "string",
                    "description": "Paragrafnummer, t.ex. '7' eller '7 a'."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Författning och paragrafer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "law": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "sfs_number": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        },
                        "short_title": {
                          "type": "string"
                        }
                      }
                    },
                    "sections": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "section_number": {
                            "type": "string"
                          },
                          "heading": {
                            "type": "string"
                          },
                          "content": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "security": [
          {
            "OAuth2": [
              "openid",
              "email",
              "profile"
            ]
          }
        ]
      }
    },
    "/v1/judgment": {
      "post": {
        "operationId": "getJudgment",
        "summary": "Hämta ett domstolsavgörande",
        "description": "Hämtar ett avgörande via målnummer eller Legaldigm-id, med domstol, datum, sammanfattning och domtext.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "case_number": {
                    "type": "string",
                    "description": "Målnummer, t.ex. 'T 1234-22'."
                  },
                  "judgment_id": {
                    "type": "string",
                    "description": "Legaldigms interna id för avgörandet."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Avgörandet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "judgment": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "case_number": {
                          "type": "string"
                        },
                        "court_name": {
                          "type": "string"
                        },
                        "judgment_date": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        },
                        "summary": {
                          "type": "string"
                        },
                        "full_text": {
                          "type": "string"
                        },
                        "legal_areas": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "security": [
          {
            "OAuth2": [
              "openid",
              "email",
              "profile"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "description": "Logga in med ditt Legaldigm-konto (ChatGPT-plugin / GPT Actions).",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://zdpjpohbmxiaykcdswsb.supabase.co/auth/v1/oauth/authorize",
            "tokenUrl": "https://zdpjpohbmxiaykcdswsb.supabase.co/auth/v1/oauth/token",
            "scopes": {
              "openid": "Identitet",
              "email": "E-post",
              "profile": "Profil"
            }
          }
        }
      }
    },
    "schemas": {
      "LegalSource": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "legislation, judgment eller international_case."
          },
          "title": {
            "type": "string"
          },
          "reference": {
            "type": "string",
            "description": "SFS-nummer, målnummer eller ECLI."
          },
          "excerpt": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "description": "Länk till källan på legaldigm.se."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Saknad, ogiltig eller spärrad API-nyckel.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "Tokensaldot räcker inte. Fyll på tokenpaket på legaldigm.se/api-nycklar.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Källan finns inte i databasen.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}