{
  "openapi": "3.1.0",
  "info": {
    "title": "CCA Export Screening API",
    "version": "1.0.0",
    "description": "Restricted-party screening against current export-control and sanctions sources. Potential matches require human review; a no-match response is not an export authorization."
  },
  "servers": [
    {
      "url": "https://exportscreening.datasourceapi.com"
    }
  ],
  "x-cloudflare-service-binding": {
    "service": "cca-export-control-api",
    "binding": "EXPORT_SCREENING",
    "wrangler_jsonc": {
      "services": [
        {
          "binding": "EXPORT_SCREENING",
          "service": "cca-export-control-api"
        }
      ]
    },
    "http_example": "env.EXPORT_SCREENING.fetch(new Request('https://exportscreening.internal/api/v1/screen', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input) }))",
    "rpc_example": "await env.EXPORT_SCREENING.screen(input)"
  },
  "paths": {
    "/api/v1/screen": {
      "post": {
        "operationId": "screenParty",
        "summary": "Screen a party",
        "description": "Returns potential matches or fails closed with INCOMPLETE when required source coverage is unavailable.",
        "x-cloudflare-service-binding": {
          "http_path": "https://exportscreening.internal/api/v1/screen",
          "rpc_method": "screen"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScreeningInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed screening",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScreeningEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "503": {
            "description": "Required source coverage is missing, stale, or unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScreeningEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/status": {
      "get": {
        "operationId": "getStatus",
        "summary": "Get source readiness and freshness",
        "x-cloudflare-service-binding": {
          "http_path": "https://exportscreening.internal/api/v1/status",
          "rpc_method": "status"
        },
        "responses": {
          "200": {
            "description": "All required sources are current"
          },
          "503": {
            "description": "At least one required source is not ready"
          }
        }
      }
    },
    "/api/v1/sources": {
      "get": {
        "operationId": "listSources",
        "summary": "List active source releases",
        "responses": {
          "200": {
            "description": "Public source inventory"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ScreeningInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 200
          },
          "entityType": {
            "type": "string",
            "enum": [
              "person",
              "organization",
              "vessel",
              "aircraft",
              "other"
            ]
          },
          "country": {
            "type": "string",
            "maxLength": 64
          },
          "dateOfBirth": {
            "type": "string",
            "maxLength": 40
          },
          "identifiers": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": [
                "value"
              ],
              "properties": {
                "kind": {
                  "type": "string",
                  "maxLength": 50
                },
                "value": {
                  "type": "string",
                  "maxLength": 100
                }
              }
            }
          },
          "threshold": {
            "type": "number",
            "minimum": 0.5,
            "maximum": 1,
            "default": 0.82
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 50,
            "default": 20
          }
        },
        "anyOf": [
          {
            "required": [
              "name"
            ]
          },
          {
            "required": [
              "identifiers"
            ]
          }
        ]
      },
      "ScreeningEnvelope": {
        "type": "object",
        "required": [
          "request_status",
          "message",
          "data",
          "meta"
        ],
        "properties": {
          "request_status": {
            "const": "success"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/ScreeningResult"
          },
          "meta": {
            "type": "object",
            "required": [
              "request_id",
              "duration_ms"
            ],
            "properties": {
              "request_id": {
                "type": "string"
              },
              "duration_ms": {
                "type": "number"
              }
            }
          }
        }
      },
      "ScreeningResult": {
        "type": "object",
        "required": [
          "decision",
          "threshold",
          "scoreVersion",
          "matches",
          "sources",
          "freshness",
          "incompleteReasons",
          "screenedAt"
        ],
        "properties": {
          "decision": {
            "type": "string",
            "enum": [
              "POTENTIAL_MATCH",
              "NO_MATCH",
              "INCOMPLETE"
            ]
          },
          "threshold": {
            "type": "number"
          },
          "scoreVersion": {
            "type": "string"
          },
          "matches": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "freshness": {
            "type": "object",
            "required": [
              "ready",
              "requiredSourcesCurrent",
              "requiredSourcesExpected",
              "oldestVerifiedAt"
            ],
            "properties": {
              "ready": {
                "type": "boolean"
              },
              "requiredSourcesCurrent": {
                "type": "integer"
              },
              "requiredSourcesExpected": {
                "type": "integer"
              },
              "oldestVerifiedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "incompleteReasons": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "screenedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
