{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/publishwith-ai/json-schema/publishwith-ai-share-response-schema.json",
  "title": "ShareResponse",
  "description": "Outcome of an additive share. Self-sufficient: it carries the artifact url, its visibility and the resulting access list, so no follow-up list_access is needed to verify. An external grant also returns share_url. An audience fan-out returns created[] + deduplicated_count.",
  "x-generated": "2026-11-22",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/publishwith-ai-openapi.yml#/components/schemas/ShareResponse",
  "type": "object",
  "properties": {
    "result_code": {
      "type": "string",
      "enum": [
        "created",
        "deduplicated",
        "upgraded",
        "unchanged",
        "conflict"
      ],
      "description": "created=new grant; deduplicated=identical grant already existed; upgraded=raised to a higher level; unchanged=already had access via visibility/group; conflict=already holds a higher level (not downgraded)."
    },
    "resolved_lane": {
      "type": "string",
      "enum": [
        "internal",
        "external"
      ]
    },
    "resolved_principal_type": {
      "type": "string",
      "enum": [
        "tenant_user",
        "tenant_group",
        "external_email",
        "audience"
      ]
    },
    "opens_via": {
      "type": "string",
      "description": "How the principal opens the artifact: 'canonical URL' or 'share link'."
    },
    "share_url": {
      "type": "string",
      "format": "uri",
      "description": "Tokenized share URL, present only for an external (link) grant."
    },
    "grant_id": {
      "type": "string",
      "description": "The created or affected grant id."
    },
    "artifact_id": {
      "type": "string"
    },
    "url": {
      "type": "string",
      "format": "uri",
      "description": "Canonical artifact URL."
    },
    "visibility": {
      "type": "string",
      "enum": [
        "private",
        "tenant",
        "public"
      ],
      "description": "The artifact's visibility floor after the share."
    },
    "access": {
      "type": "array",
      "description": "Every live grant on the artifact after this call, same shape as list_access.",
      "items": {
        "type": "object",
        "properties": {
          "grant_id": {
            "type": "string"
          },
          "principal_type": {
            "type": "string",
            "enum": [
              "tenant_user",
              "tenant_group",
              "external_email"
            ]
          },
          "principal": {
            "type": "string"
          },
          "access_level": {
            "type": "string",
            "enum": [
              "view",
              "edit",
              "own"
            ]
          },
          "delivery": {
            "type": "string",
            "enum": [
              "canonical",
              "link",
              "email"
            ]
          },
          "source": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    },
    "current_access_level": {
      "type": "string",
      "description": "On a conflict, the principal's existing (higher) access level."
    },
    "created": {
      "type": "array",
      "description": "For an audience fan-out, the per-contact links created.",
      "items": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string"
          },
          "share_url": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    },
    "deduplicated_count": {
      "type": "integer",
      "description": "For an audience fan-out, the number of contacts skipped because they already had a live grant."
    }
  }
}