{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://layerscope.kitdev.space/schema/report-1.json",
  "title": "layerscope check --format json, version 1",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "source", "notes", "layers", "summary", "findings"],
  "properties": {
    "version": { "const": 1, "description": "Raised only on breaking changes to the shape." },
    "source": { "enum": ["registry", "types"], "description": "Where symbols were read from." },
    "notes": { "type": "array", "items": { "type": "string" } },
    "layers": {
      "type": "array",
      "description": "Every layer in priority order.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "root"],
        "properties": {
          "name": { "type": "string" },
          "root": { "type": "string", "description": "Relative to the working directory." }
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["files", "errors", "warnings"],
      "properties": {
        "files": { "type": "integer", "minimum": 0 },
        "errors": { "type": "integer", "minimum": 0 },
        "warnings": { "type": "integer", "minimum": 0 }
      }
    },
    "findings": {
      "type": "array",
      "description": "Sorted by file, line, column, rule and symbol.",
      "items": { "$ref": "#/$defs/finding" }
    },
    "baseline": {
      "type": "object",
      "description": "Only when a baseline file exists.",
      "additionalProperties": false,
      "required": ["file", "suppressed", "removable"],
      "properties": {
        "file": { "type": "string" },
        "suppressed": {
          "type": "array",
          "description": "Findings the baseline accepts.",
          "items": { "$ref": "#/$defs/finding" }
        },
        "removable": {
          "type": "array",
          "description": "Entries that no longer occur.",
          "items": { "$ref": "#/$defs/baselineEntry" }
        }
      }
    }
  },
  "$defs": {
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "rule",
        "severity",
        "file",
        "line",
        "column",
        "symbol",
        "fromLayer",
        "toLayer",
        "target",
        "message"
      ],
      "properties": {
        "rule": {
          "enum": [
            "layer-boundary",
            "layer-cycle",
            "layer-internal",
            "unresolved-reference",
            "shadowed-component",
            "shadowed-layout",
            "shadowed-middleware",
            "shadowed-page",
            "shadowed-server-route",
            "shadowed-auto-import"
          ]
        },
        "severity": { "enum": ["error", "warn"] },
        "file": { "type": "string", "description": "Relative to the working directory." },
        "line": { "type": "integer", "minimum": 1 },
        "column": { "type": "integer", "minimum": 1 },
        "symbol": {
          "type": "string",
          "description": "Identifier, component name, import specifier, a layer-cycle chain, the name or path of an overridden file, or the route of an overridden server route file (for example `GET /api/hello`)."
        },
        "fromLayer": { "type": "string", "description": "The layer the file belongs to." },
        "toLayer": {
          "type": ["string", "null"],
          "description": "The layer the symbol resolves to; null for packages and unresolved references, and for a shadowed rule when the winner is in no layer."
        },
        "target": {
          "type": ["string", "null"],
          "description": "File the symbol resolves to, when known."
        },
        "allowed": {
          "type": "array",
          "description": "layer-boundary only: the layers fromLayer may use whole.",
          "items": { "type": "string" }
        },
        "scoped": {
          "type": "array",
          "description": "layer-boundary only: the layers fromLayer may use in part.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["layer", "only"],
            "properties": {
              "layer": { "type": "string" },
              "only": { "type": "array", "items": { "type": "string" } }
            }
          }
        },
        "exposed": {
          "type": "array",
          "description": "layer-internal only: what toLayer makes public.",
          "items": { "type": "string" }
        },
        "unread": {
          "const": true,
          "description": "unresolved-reference only: true when layerscope parsed the file but could not read a part of it."
        },
        "suggestion": { "$ref": "#/$defs/suggestion" },
        "message": { "type": "string" }
      }
    },
    "suggestion": {
      "type": "object",
      "description": "layer-boundary and layer-internal only.",
      "additionalProperties": false,
      "required": ["action", "message", "impact"],
      "properties": {
        "action": { "enum": ["move", "allow", "expose", "leave"] },
        "message": { "type": "string" },
        "layer": { "type": "string", "description": "move: the layer to move the file to." },
        "only": {
          "type": "array",
          "description": "allow: the names of a scoped entry, when the whole layer is not needed.",
          "items": { "type": "string" }
        },
        "expose": {
          "type": "string",
          "description": "expose: the name or glob to add to the expose list of the layer."
        },
        "file": {
          "type": "string",
          "description": "move: where the file lands, relative to the working directory."
        },
        "impact": {
          "type": "object",
          "additionalProperties": false,
          "required": ["fixes"],
          "properties": {
            "fixes": {
              "type": "integer",
              "minimum": 0,
              "description": "The findings that the suggestion clears, among the findings that the report shows. For a move: the findings that point at the file and the findings in it."
            },
            "files": {
              "type": "integer",
              "minimum": 0,
              "description": "move: the files that use the moved file."
            },
            "imports": {
              "type": "integer",
              "minimum": 0,
              "description": "move: the imports that `layerscope fix` lists for the move: relative specifiers that change and aliases to update by hand, in the users and in the moved file."
            },
            "edges": {
              "type": "integer",
              "minimum": 0,
              "description": "allow: the edges that the suggestion adds to the allow map."
            }
          }
        }
      }
    },
    "baselineEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rule", "file", "symbol", "toLayer"],
      "properties": {
        "rule": {
          "enum": [
            "layer-boundary",
            "layer-cycle",
            "layer-internal",
            "unresolved-reference",
            "shadowed-component",
            "shadowed-layout",
            "shadowed-middleware",
            "shadowed-page",
            "shadowed-server-route",
            "shadowed-auto-import"
          ]
        },
        "file": { "type": "string" },
        "symbol": { "type": "string" },
        "toLayer": { "type": ["string", "null"] },
        "count": { "type": "integer", "minimum": 1 }
      }
    }
  }
}
