{
  "openapi": "3.1.0",
  "info": {
    "title": "Heimdal API",
    "version": "1.0.0",
    "summary": "Sign-up fraud checks for email and IP addresses.",
    "description": "One call checks an email address, an IP address or both at sign-up.",
    "license": {
      "name": "Proprietary",
      "url": "https://heimdal.codebrewerz.com/eula"
    }
  },
  "servers": [
    {
      "url": "https://heimdal.codebrewerz.com/api"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/v1/check": {
      "get": {
        "operationId": "checkGet",
        "summary": "Check with query parameters",
        "parameters": [
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 320
            },
            "example": "test@mailinator.com"
          },
          {
            "name": "ip",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 320
            },
            "example": "185.220.101.1"
          }
        ],
        "responses": {
          "200": {
            "description": "The check. `block` is true when any signal fired.",
            "headers": {
              "RateLimit-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: the key's limit, e.g. \"shield\";q=100;w=1"
              },
              "RateLimit": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: requests left and seconds to reset, e.g. \"shield\";r=99;t=1"
              },
              "Heimdal-Degraded": {
                "schema": {
                  "type": "string"
                },
                "description": "Present when part of the answer is missing: `custom_lists`."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckResult"
                }
              }
            }
          },
          "400": {
            "description": "The input cannot be checked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "value": {
                      "error": {
                        "code": "invalid_request",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_ip": {
                    "value": {
                      "error": {
                        "code": "invalid_ip",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_email": {
                    "value": {
                      "error": {
                        "code": "invalid_email",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No API key, or not a valid one.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "missing_api_key": {
                    "value": {
                      "error": {
                        "code": "missing_api_key",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_api_key": {
                    "value": {
                      "error": {
                        "code": "invalid_api_key",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "The account has no active subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "subscription_required": {
                    "value": {
                      "error": {
                        "code": "subscription_required",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "The body is over 16 KB.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "payload_too_large": {
                    "value": {
                      "error": {
                        "code": "payload_too_large",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this key, or too many bad keys from this address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rate_limited": {
                    "value": {
                      "error": {
                        "code": "rate_limited",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "RateLimit-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: the limit that was hit. Per key: \"shield\";q=100;w=1. Missing or invalid keys from one address: \"bad-key\";q=30;w=60"
              },
              "RateLimit": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: requests left and seconds to reset, e.g. \"shield\";r=99;t=1"
              },
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait: 1 for the per-key limit, up to 60 for bad keys."
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable. Retry, and let the sign-up through meanwhile.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait. Sent while Heimdal restarts."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "lists_unavailable": {
                    "value": {
                      "error": {
                        "code": "lists_unavailable",
                        "message": "..."
                      }
                    }
                  },
                  "service_unavailable": {
                    "value": {
                      "error": {
                        "code": "service_unavailable",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "checkPost",
        "summary": "Check with a JSON body",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The check. `block` is true when any signal fired.",
            "headers": {
              "RateLimit-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: the key's limit, e.g. \"shield\";q=100;w=1"
              },
              "RateLimit": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: requests left and seconds to reset, e.g. \"shield\";r=99;t=1"
              },
              "Heimdal-Degraded": {
                "schema": {
                  "type": "string"
                },
                "description": "Present when part of the answer is missing: `custom_lists`."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckResult"
                }
              }
            }
          },
          "400": {
            "description": "The input cannot be checked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "value": {
                      "error": {
                        "code": "invalid_request",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_ip": {
                    "value": {
                      "error": {
                        "code": "invalid_ip",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_email": {
                    "value": {
                      "error": {
                        "code": "invalid_email",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No API key, or not a valid one.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "missing_api_key": {
                    "value": {
                      "error": {
                        "code": "missing_api_key",
                        "message": "..."
                      }
                    }
                  },
                  "invalid_api_key": {
                    "value": {
                      "error": {
                        "code": "invalid_api_key",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "The account has no active subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "subscription_required": {
                    "value": {
                      "error": {
                        "code": "subscription_required",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "The body is over 16 KB.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "payload_too_large": {
                    "value": {
                      "error": {
                        "code": "payload_too_large",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this key, or too many bad keys from this address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rate_limited": {
                    "value": {
                      "error": {
                        "code": "rate_limited",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "RateLimit-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: the limit that was hit. Per key: \"shield\";q=100;w=1. Missing or invalid keys from one address: \"bad-key\";q=30;w=60"
              },
              "RateLimit": {
                "schema": {
                  "type": "string"
                },
                "description": "IETF draft: requests left and seconds to reset, e.g. \"shield\";r=99;t=1"
              },
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait: 1 for the per-key limit, up to 60 for bad keys."
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable. Retry, and let the sign-up through meanwhile.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait. Sent while Heimdal restarts."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "lists_unavailable": {
                    "value": {
                      "error": {
                        "code": "lists_unavailable",
                        "message": "..."
                      }
                    }
                  },
                  "service_unavailable": {
                    "value": {
                      "error": {
                        "code": "service_unavailable",
                        "message": "..."
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer hd_..."
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "CheckInput": {
        "type": "object",
        "description": "At least one field. `null` or an empty string means not sent; other fields are ignored.",
        "properties": {
          "email": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 320,
            "description": "Email address",
            "example": "test@mailinator.com"
          },
          "ip": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 320,
            "description": "IPv4 or IPv6 address",
            "example": "185.220.101.1"
          }
        }
      },
      "CheckResult": {
        "type": "object",
        "required": [
          "block",
          "reasons",
          "email",
          "ip",
          "custom"
        ],
        "properties": {
          "block": {
            "type": "boolean"
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "disposable_email",
                "tor",
                "proxy",
                "vpn",
                "bad_isp",
                "custom_list"
              ]
            }
          },
          "email": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "address",
                  "domain",
                  "disposable"
                ],
                "properties": {
                  "address": {
                    "type": "string"
                  },
                  "domain": {
                    "type": "string"
                  },
                  "disposable": {
                    "type": "boolean"
                  }
                }
              }
            ]
          },
          "ip": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "address",
                  "tor",
                  "vpn",
                  "proxy",
                  "bad_isp",
                  "asn",
                  "isp"
                ],
                "properties": {
                  "address": {
                    "type": "string"
                  },
                  "tor": {
                    "type": "boolean"
                  },
                  "vpn": {
                    "type": "boolean"
                  },
                  "proxy": {
                    "type": "boolean"
                  },
                  "bad_isp": {
                    "type": "boolean"
                  },
                  "asn": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "isp": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            ]
          },
          "custom": {
            "type": "object",
            "required": [
              "matched"
            ],
            "properties": {
              "matched": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "list",
                    "kind",
                    "value"
                  ],
                  "properties": {
                    "list": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "email",
                        "domain",
                        "ip",
                        "cidr"
                      ]
                    },
                    "value": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "invalid_ip",
                  "invalid_email",
                  "missing_api_key",
                  "invalid_api_key",
                  "subscription_required",
                  "payload_too_large",
                  "rate_limited",
                  "lists_unavailable",
                  "service_unavailable"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}