{
  "openapi": "3.0.3",
  "info": {
    "title": "Larchmont Industries Legal Ops API",
    "version": "1.0.0",
    "description": "A made-up corporate legal department's API, for testing MatterSeal firm connections. Larchmont and its data are fictional."
  },
  "components": {
    "securitySchemes": {
      "oauth": {"type": "oauth2", "flows": {"clientCredentials": {"tokenUrl": "/oauth/token", "scopes": {"matters": "", "invoices": "", "documents": ""}}}},
      "apiKey": {"type": "apiKey", "in": "header", "name": "X-Api-Key"}
    },
    "schemas": {
      "Engagement": {"type": "object", "properties": {
        "engagement_ref": {"type": "string"}, "title": {"type": "string"}, "business_unit": {"type": "string"},
        "status": {"type": "string", "enum": ["open", "closed"]}, "outside_counsel": {"type": "string"},
        "opened_on": {"type": "string", "format": "date"}}},
      "MatterRequest": {"type": "object", "properties": {
        "request_id": {"type": "string"}, "request_title": {"type": "string"}, "business_unit": {"type": "string"},
        "requested_by": {"type": "object", "properties": {"name": {"type": "string"}, "email": {"type": "string"}}},
        "priority": {"type": "string", "enum": ["low", "normal", "high"]},
        "submitted_at": {"type": "string", "format": "date-time"}, "description": {"type": "string"}}},
      "InvoiceLine": {"type": "object", "required": ["date", "timekeeper", "hours", "rate_cents", "amount_cents", "description"], "properties": {
        "date": {"type": "string", "format": "date"}, "timekeeper": {"type": "string"}, "task_code": {"type": "string"},
        "hours": {"type": "string", "example": "1.25"}, "rate_cents": {"type": "integer"}, "amount_cents": {"type": "integer"},
        "description": {"type": "string"}}},
      "Invoice": {"type": "object", "required": ["invoice_no", "period_start", "period_end", "currency", "amount_cents", "lines"], "properties": {
        "invoice_no": {"type": "string", "maxLength": 20}, "period_start": {"type": "string", "format": "date"},
        "period_end": {"type": "string", "format": "date"}, "currency": {"type": "string", "enum": ["USD"]},
        "amount_cents": {"type": "integer"}, "lines": {"type": "array", "items": {"$ref": "#/components/schemas/InvoiceLine"}}}},
      "InvoiceReceipt": {"type": "object", "properties": {
        "invoice_id": {"type": "string"}, "status": {"type": "string"}, "received_at": {"type": "string", "format": "date-time"}}},
      "Problem": {"type": "object", "properties": {
        "error": {"type": "string"}, "detail": {"type": "string"}, "fields": {"type": "object", "additionalProperties": {"type": "string"}}}}
    }
  },
  "security": [{"oauth": []}, {"apiKey": []}],
  "paths": {
    "/v1/engagements": {"get": {"operationId": "listEngagements", "summary": "Matters Larchmont has with outside counsel",
      "parameters": [{"name": "status", "in": "query", "schema": {"type": "string", "enum": ["open", "closed"]}}],
      "responses": {"200": {"description": "Engagements", "content": {"application/json": {"schema": {"type": "object", "properties": {"data": {"type": "array", "items": {"$ref": "#/components/schemas/Engagement"}}}}}}}}}},
    "/v1/matter-requests": {"get": {"operationId": "listMatterRequests", "summary": "New matters Larchmont asks outside counsel to take",
      "parameters": [{"name": "since", "in": "query", "schema": {"type": "string", "format": "date-time"}}],
      "responses": {"200": {"description": "Requests", "content": {"application/json": {"schema": {"type": "object", "properties": {"data": {"type": "array", "items": {"$ref": "#/components/schemas/MatterRequest"}}}}}}}}}},
    "/v1/engagements/{engagement_ref}/invoices": {"post": {"operationId": "submitInvoice", "summary": "Send an invoice for an engagement",
      "parameters": [{"name": "engagement_ref", "in": "path", "required": true, "schema": {"type": "string"}},
        {"name": "Idempotency-Key", "in": "header", "required": true, "schema": {"type": "string", "maxLength": 100}}],
      "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Invoice"}}}},
      "responses": {"201": {"description": "Received", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/InvoiceReceipt"}}}},
        "409": {"description": "That invoice number was already received"},
        "422": {"description": "The invoice doesn't add up", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Problem"}}}},
        "429": {"description": "Too many calls; see Retry-After"}}}},
    "/v1/invoices/{invoice_id}": {"get": {"operationId": "getInvoice", "summary": "An invoice as Larchmont received it",
      "parameters": [{"name": "invoice_id", "in": "path", "required": true, "schema": {"type": "string"}}],
      "responses": {"200": {"description": "The invoice"}, "404": {"description": "No such invoice"}}}},
    "/v1/documents": {"post": {"operationId": "uploadDocument", "summary": "Send a document for an engagement",
      "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["engagement_ref", "file_name", "content_base64"], "properties": {
        "engagement_ref": {"type": "string"}, "file_name": {"type": "string"}, "content_base64": {"type": "string", "format": "byte"}}}}}},
      "responses": {"201": {"description": "Received"}, "422": {"description": "Not a document Larchmont takes"}}}}
  }
}
