{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://skillcatalog.dev/schemas/consumer-profile.schema.json",
  "title": "SkillCatalog Consumer Profile",
  "description": "Reusable selections read from the named file in a verified repository snapshot. Contributes entries to the consuming installed profile; it has no identity, destination, or private settings. Runtime checks catalog identity, entry references, source agreement, links, byte limits, and the transitive graph.",
  "type": "object",
  "required": [
    "entries"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "entries": {
            "type": "array",
            "minItems": 1
          }
        },
        "required": [
          "entries"
        ]
      },
      "then": {
        "required": [
          "catalogs"
        ],
        "properties": {
          "catalogs": {
            "type": "object",
            "minProperties": 1
          }
        }
      }
    }
  ],
  "properties": {
    "catalogs": {
      "type": [
        "object",
        "null"
      ],
      "description": "Catalogs used by direct entries. May be omitted, null, or empty when entries is empty. Each key must match catalog.yaml at the selected source.",
      "propertyNames": {
        "minLength": 2,
        "maxLength": 64,
        "pattern": "^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,127}$"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "$ref": "skillcatalog-yml.schema.json#/properties/catalogs/additionalProperties"
          },
          {
            "type": "object",
            "required": [
              "source"
            ],
            "additionalProperties": false,
            "properties": {
              "source": {
                "const": "self",
                "description": "The containing import source at its exact resolved commit. Valid only in verified import context; no separate revision is allowed."
              }
            }
          }
        ]
      }
    },
    "entries": {
      "$ref": "skillcatalog-yml.schema.json#/properties/entries"
    },
    "imports": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/profileImport"
      },
      "description": "Ordered explicit imports. Each consumer contributes its direct entries before its child imports. Runtime limits the complete graph."
    }
  },
  "$defs": {
    "profileImport": {
      "type": "object",
      "required": [
        "source",
        "revision",
        "path"
      ],
      "additionalProperties": false,
      "properties": {
        "source": {
          "type": "string",
          "allOf": [
            {
              "type": "string",
              "minLength": 1,
              "anyOf": [
                {
                  "pattern": "^git@[^\\s?#]*$"
                },
                {
                  "pattern": "^[Ss][Ss][Hh]://(?![^\\s?#/]*:[^\\s?#/]*@)[^\\s?#]*$"
                },
                {
                  "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://[^/?#\\s@]+(?:/[^\\s?#]*)?$"
                }
              ],
              "description": "Remote Git catalog source. Accepts git@host:path, ssh:// (scheme case-insensitive; user, port, IPv6 literal and colon-path forms all allowed, but no password in the userinfo), and HTTP(S) with a non-empty authority and no userinfo. Query strings, fragments, embedded whitespace, local filesystem paths and file:// URLs are rejected."
            },
            {
              "pattern": "^(?:git@(?:\\[(?!-)[^\\]]+\\]|(?:[^:]*@)?(?![-@:\\[])[^:@\\[]+):/*[^/][\\s\\S]*|[Ss][Ss][Hh]://(?:[^/]*@)?(?:\\[(?!-)[^\\]]+\\][^/]*|(?![-:@/\\[])[^:@/]+(?::[^/]*)?)/+[^/][\\s\\S]*|[Hh][Tt][Tt][Pp][Ss]?://(?:\\[(?!-)[^\\]]+\\][^/]*|(?![-:@/\\[])[^:@/]+(?::[^/]*)?)/+[^/][\\s\\S]*)$(?![\\s\\S])"
            },
            {
              "not": {
                "pattern": "[\\u0000-\\u001f\\u007f-\\u009f\\\\]"
              }
            }
          ],
          "description": "Remote Git source with a nonempty host and repository path. Uses the catalog-source rules and rejects self, local paths, controls, backslashes, and option-shaped hosts."
        },
        "revision": {
          "$ref": "skillcatalog-yml.schema.json#/$defs/catalogRevision"
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096,
          "pattern": "^(?![A-Za-z]:)(?![sS][kK][iI][lL][lL][cC][aA][tT][aA][lL][oO][gG]\\.[lL][oO][cC][aA][lL]\\.[yY][mM][lL]$(?![\\s\\S]))(?!\\.[sS][kK][iI][lL][lL][cC][aA][tT][aA][lL][oO][gG]/[sS][kK][iI][lL][lL][cC][aA][tT][aA][lL][oO][gG]\\.[lL][oO][cC][aA][lL]\\.[yY][mM][lL]$(?![\\s\\S]))(?!(?:[^/]*/)*[.][gG][iI][tT](?:/|$(?![\\s\\S])))(?:(?!\\.{1,2}(?:/|$(?![\\s\\S])))[^/\\\\\\u0000-\\u001f\\u007f-\\u009f]{1,255}/){0,31}(?!\\.{1,2}$(?![\\s\\S]))[^/\\\\\\u0000-\\u001f\\u007f-\\u009f]{1,255}$(?![\\s\\S])",
          "description": "File relative to the repository root. Rejects absolute and drive-prefixed paths, empty/current/parent components, .git components in any case, controls, backslashes, and current or legacy local manifests. At most 32 components, 255 UTF-8 bytes per component, and 4096 UTF-8 bytes total; the runtime enforces byte limits and rejects symlinks, hard links, and nonregular files."
        }
      }
    }
  }
}
