{
  "openapi": "3.1.0",
  "info": {
    "title": "Fare API",
    "version": "0.1.0",
    "description": "Small, exact APIs priced per call. Failed calls are never billed."
  },
  "servers": [
    {
      "url": "https://api.fare.dev"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Check": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "pass",
              "warn",
              "fail",
              "unknown"
            ]
          },
          "points": {
            "type": "integer"
          },
          "max_points": {
            "type": "integer"
          },
          "record": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "PdfReport": {
        "type": "object",
        "required": [
          "profile",
          "compliant",
          "failed_rules",
          "violations"
        ],
        "properties": {
          "profile": {
            "type": "string",
            "enum": [
              "PDF/UA-1",
              "PDF/UA-2"
            ]
          },
          "compliant": {
            "type": "boolean"
          },
          "failed_rules": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Distinct veraPDF rule ids that failed, e.g. 7.1-t03"
          },
          "violations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "rule": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "rule_set": {
            "type": "string"
          }
        }
      },
      "EmailGrade": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string"
          },
          "grade": {
            "type": "string",
            "enum": [
              "A",
              "B",
              "C",
              "D",
              "F"
            ]
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "spf": {
            "$ref": "#/components/schemas/Check"
          },
          "dmarc": {
            "$ref": "#/components/schemas/Check"
          },
          "dkim": {
            "$ref": "#/components/schemas/Check"
          },
          "mx": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "accepts_mail": {
            "type": "boolean"
          },
          "fixes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "RemediationReport": {
        "type": "object",
        "properties": {
          "compliant": {
            "type": "boolean"
          },
          "remaining_rules": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "violations_before": {
            "type": "integer"
          },
          "violations_after": {
            "type": "integer"
          },
          "fixes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "area": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "review": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "area": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "outline": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "pdf_base64": {
            "type": "string",
            "contentEncoding": "base64"
          }
        }
      }
    }
  },
  "paths": {
    "/v1/pdf/validate": {
      "post": {
        "operationId": "validatePdf",
        "summary": "Validate a PDF against PDF/UA-1 or PDF/UA-2",
        "parameters": [
          {
            "name": "profile",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ua1",
                "ua2",
                "auto"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PdfReport"
                }
              }
            }
          },
          "400": {
            "description": "Bad input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Unreadable PDF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or quota",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/email-grade": {
      "get": {
        "operationId": "gradeEmailSecurity",
        "summary": "Grade a domain's SPF, DKIM and DMARC",
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "selector",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Grade",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailGrade"
                }
              }
            }
          },
          "400": {
            "description": "Bad input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or quota",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "DNS failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/pdf/remediate": {
      "post": {
        "operationId": "remediatePdf",
        "summary": "Tag and repair a PDF for PDF/UA-1",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "title",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "pdf",
                "json"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Remediated PDF (format=pdf) or report (format=json)",
            "headers": {
              "Fare-Compliant": {
                "schema": {
                  "type": "string"
                }
              },
              "Fare-Remaining-Rules": {
                "schema": {
                  "type": "string"
                }
              },
              "Fare-Review-Items": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RemediationReport"
                }
              }
            }
          },
          "400": {
            "description": "Bad input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Unreadable PDF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or quota",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}