{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dmarc4all.toppymicros.com/schemas/diagnosis-result.schema.json",
  "title": "DMARC4all portable diagnosis report",
  "description": "Machine-readable export of a DMARC4all public-DNS diagnosis. It does not represent receiver-side DMARC conformance or message-level authentication.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "format",
    "schemaVersion",
    "generatedAt",
    "domain",
    "locale",
    "scope",
    "summary",
    "observations",
    "priorities",
    "remediation",
    "evidence",
    "errors"
  ],
  "properties": {
    "$schema": {
      "const": "https://dmarc4all.toppymicros.com/schemas/diagnosis-result.schema.json"
    },
    "format": {
      "const": "dmarc4all-diagnosis"
    },
    "schemaVersion": {
      "const": "1.0.0"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "domain": {
      "type": "string",
      "minLength": 1
    },
    "locale": {
      "type": "string",
      "minLength": 2
    },
    "scope": {
      "$ref": "#/$defs/scope"
    },
    "summary": {
      "$ref": "#/$defs/summary"
    },
    "observations": {
      "$ref": "#/$defs/observations"
    },
    "priorities": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/priority"
      }
    },
    "remediation": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/remediation"
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "dnsRecords"
      ],
      "properties": {
        "dnsRecords": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/dnsRecord"
          }
        }
      }
    },
    "errors": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "$defs": {
    "nullableScore": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 100
    },
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "basis",
        "resolver",
        "limitations"
      ],
      "properties": {
        "basis": {
          "const": "public_dns"
        },
        "resolver": {
          "type": "string"
        },
        "limitations": {
          "type": "array",
          "items": {
            "enum": [
              "no_email_sent_or_received",
              "no_mailbox_or_server_access",
              "dkim_selectors_not_exhaustively_discoverable",
              "results_require_header_and_rua_confirmation"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scores",
        "enforcementReadiness",
        "mailProvider"
      ],
      "properties": {
        "scores": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "overall",
            "spf"
          ],
          "properties": {
            "overall": {
              "$ref": "#/$defs/nullableScore"
            },
            "spf": {
              "$ref": "#/$defs/nullableScore"
            }
          }
        },
        "enforcementReadiness": {
          "$ref": "#/$defs/readiness"
        },
        "mailProvider": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "name",
            "confidence",
            "signals"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "confidence": {
              "type": "string"
            },
            "signals": {
              "$ref": "#/$defs/stringArray"
            }
          }
        }
      }
    },
    "readiness": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "level",
        "policy",
        "checks",
        "blockers"
      ],
      "properties": {
        "status": {
          "enum": [
            "monitoring_only",
            "ready_for_quarantine",
            "ready_for_reject",
            "reject_enforced"
          ]
        },
        "level": {
          "enum": [
            "good",
            "warn",
            "bad"
          ]
        },
        "policy": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "none",
            "quarantine",
            "reject",
            null
          ]
        },
        "checks": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "dmarcRecordPresent",
            "dmarcPolicyValid",
            "aggregateReportingConfigured",
            "spfUsable",
            "dkimConfirmed"
          ],
          "properties": {
            "dmarcRecordPresent": {
              "type": "boolean"
            },
            "dmarcPolicyValid": {
              "type": "boolean"
            },
            "aggregateReportingConfigured": {
              "type": "boolean"
            },
            "spfUsable": {
              "type": "boolean"
            },
            "dkimConfirmed": {
              "type": "boolean"
            }
          }
        },
        "blockers": {
          "type": "array",
          "items": {
            "enum": [
              "dmarc_record_missing",
              "dmarc_policy_invalid",
              "aggregate_reporting_missing",
              "spf_not_usable",
              "dkim_not_confirmed"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "observations": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "dmarc",
        "spf",
        "dkim",
        "bimi",
        "mx",
        "mtaSts",
        "caa",
        "dnssec",
        "subdomains"
      ],
      "properties": {
        "dmarc": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "record",
            "policy",
            "aggregateReportingConfigured"
          ],
          "properties": {
            "record": {
              "type": "string"
            },
            "policy": {
              "type": [
                "string",
                "null"
              ]
            },
            "aggregateReportingConfigured": {
              "type": "boolean"
            }
          }
        },
        "spf": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "records",
            "recordCount",
            "dangerousAll"
          ],
          "properties": {
            "records": {
              "$ref": "#/$defs/stringArray"
            },
            "recordCount": {
              "type": "integer",
              "minimum": 0
            },
            "dangerousAll": {
              "type": "boolean"
            }
          }
        },
        "dkim": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "selectors",
            "confirmedSelectors",
            "usesCname"
          ],
          "properties": {
            "selectors": {
              "$ref": "#/$defs/stringArray"
            },
            "confirmedSelectors": {
              "$ref": "#/$defs/stringArray"
            },
            "usesCname": {
              "type": "boolean"
            }
          }
        },
        "bimi": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "name",
            "record",
            "logoUrl",
            "evidenceDocumentUrl"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "record": {
              "type": "string"
            },
            "logoUrl": {
              "type": "string"
            },
            "evidenceDocumentUrl": {
              "type": "string"
            }
          }
        },
        "mx": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "records"
          ],
          "properties": {
            "records": {
              "$ref": "#/$defs/stringArray"
            }
          }
        },
        "mtaSts": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "record",
            "tlsReportingRecord"
          ],
          "properties": {
            "record": {
              "type": "string"
            },
            "tlsReportingRecord": {
              "type": "string"
            }
          }
        },
        "caa": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "records"
          ],
          "properties": {
            "records": {
              "$ref": "#/$defs/stringArray"
            }
          }
        },
        "dnssec": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "ds",
            "dnskey"
          ],
          "properties": {
            "ds": {
              "$ref": "#/$defs/stringArray"
            },
            "dnskey": {
              "$ref": "#/$defs/stringArray"
            }
          }
        },
        "subdomains": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "scanEnabled",
            "found"
          ],
          "properties": {
            "scanEnabled": {
              "type": "boolean"
            },
            "found": {
              "$ref": "#/$defs/stringArray"
            }
          }
        }
      }
    },
    "priority": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "severity",
        "title",
        "action"
      ],
      "properties": {
        "severity": {
          "enum": [
            "high",
            "med",
            "low"
          ]
        },
        "title": {
          "type": "string"
        },
        "action": {
          "type": "string"
        }
      }
    },
    "remediation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "severity",
        "title",
        "summary",
        "records",
        "verify",
        "rollback"
      ],
      "properties": {
        "severity": {
          "enum": [
            "high",
            "med",
            "low"
          ]
        },
        "title": {
          "type": "string"
        },
        "summary": {
          "type": "string"
        },
        "records": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/fixRecord"
          }
        },
        "verify": {
          "type": "string"
        },
        "rollback": {
          "type": "string"
        }
      }
    },
    "fixRecord": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label",
        "host",
        "type",
        "currentValue",
        "suggestedValue",
        "copyText"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "host": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "currentValue": {
          "type": "string"
        },
        "suggestedValue": {
          "type": "string"
        },
        "copyText": {
          "type": "string"
        }
      }
    },
    "dnsRecord": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "type",
        "ttl",
        "value"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "ttl": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "value": {
          "type": "string"
        }
      }
    }
  }
}
