Summary
Create a formal JSON Schema (Draft 2020-12) for gaze crap --format=json output and wire it into the gaze schema command. This is the feature request portion of #118.
Parent issue: #118
Depends on: #140 (positional arg support must exist first)
Problem
The CRAP JSON output is the most likely to be machine-consumed by CI scripts and dashboards, but has no formal JSON Schema. The docs/reference/json-schemas.md:119 explicitly notes: "The CRAP JSON output is not covered by a formal embedded schema."
Scope Decisions Required
1. Output mode scoping
gaze crap produces two different JSON structures:
- Normal mode:
crap.Report — scores []Score + summary Summary
- Baseline comparison mode (
--baseline): crap.ComparisonResult — deltas, new_functions, removed_functions, comparison
Decision needed: Does the schema cover both output modes, or only the standard crap.Report? Options:
- (a) Schema covers only
crap.Report; document that --baseline produces a different structure
- (b) Schema uses
oneOf to cover both shapes
- (c) Two separate schemas:
CRAPSchema and CRAPComparisonSchema
2. Forward compatibility
Consider adding additionalProperties: true to allow additive field changes without breaking downstream validation. The CRAP output has gained 6 new fields across recent releases.
Proposed Changes
1. New constant in internal/report/schema.go
CRAPSchema constant (~200-300 lines) covering crap.Report:
Score struct: 14 JSON fields (8 optional with omitempty)
Summary struct: ~15 JSON fields (8 optional)
RecommendedAction struct: 10 JSON fields
- Enum types:
Quadrant (4 values), FixStrategy (4 values)
- Follow existing pattern: Draft 2020-12,
$id URL, $defs for shared types, description on every field
2. CLI wiring
Add "crap" to ValidArgs in newSchemaCmd() and dispatch to report.CRAPSchema.
3. Tests (round-trip, not hand-crafted)
TestCRAPSchema_Compiles — schema is valid Draft 2020-12
TestCRAPSchema_ValidatesMinimalOutput — minimal Report with one Score
TestCRAPSchema_ValidatesFullOutput — all optional fields populated
TestCRAPSchema_ValidatesEmptyScores — empty scores array
TestCRAPWriteJSON_ValidAgainstSchema — actual WriteJSON() output validated against schema (critical round-trip test)
4. Documentation
docs/reference/json-schemas.md — add annotated CRAP schema section
docs/reference/cli/schema.md — add crap to argument list and examples
Risks
- Maintenance ratchet: Every future field addition to
Score/Summary requires a schema update
- Schema drift: Manually-maintained Go string constants have no automated drift detection against struct tags
- Baseline mode: If not covered by the schema, users may be confused when
--baseline output fails validation
Note on report output
Per the review council analysis on #118, gaze report --format=json should NOT get a schema. It is explicitly documented as "an internal format" (json-schemas.md:352), uses json.RawMessage fields, and CI integration uses threshold flags rather than schema validation.
Summary
Create a formal JSON Schema (Draft 2020-12) for
gaze crap --format=jsonoutput and wire it into thegaze schemacommand. This is the feature request portion of #118.Parent issue: #118
Depends on: #140 (positional arg support must exist first)
Problem
The CRAP JSON output is the most likely to be machine-consumed by CI scripts and dashboards, but has no formal JSON Schema. The
docs/reference/json-schemas.md:119explicitly notes: "The CRAP JSON output is not covered by a formal embedded schema."Scope Decisions Required
1. Output mode scoping
gaze crapproduces two different JSON structures:crap.Report—scores []Score+summary Summary--baseline):crap.ComparisonResult—deltas,new_functions,removed_functions,comparisonDecision needed: Does the schema cover both output modes, or only the standard
crap.Report? Options:crap.Report; document that--baselineproduces a different structureoneOfto cover both shapesCRAPSchemaandCRAPComparisonSchema2. Forward compatibility
Consider adding
additionalProperties: trueto allow additive field changes without breaking downstream validation. The CRAP output has gained 6 new fields across recent releases.Proposed Changes
1. New constant in
internal/report/schema.goCRAPSchemaconstant (~200-300 lines) coveringcrap.Report:Scorestruct: 14 JSON fields (8 optional withomitempty)Summarystruct: ~15 JSON fields (8 optional)RecommendedActionstruct: 10 JSON fieldsQuadrant(4 values),FixStrategy(4 values)$idURL,$defsfor shared types,descriptionon every field2. CLI wiring
Add
"crap"toValidArgsinnewSchemaCmd()and dispatch toreport.CRAPSchema.3. Tests (round-trip, not hand-crafted)
TestCRAPSchema_Compiles— schema is valid Draft 2020-12TestCRAPSchema_ValidatesMinimalOutput— minimalReportwith oneScoreTestCRAPSchema_ValidatesFullOutput— all optional fields populatedTestCRAPSchema_ValidatesEmptyScores— empty scores arrayTestCRAPWriteJSON_ValidAgainstSchema— actualWriteJSON()output validated against schema (critical round-trip test)4. Documentation
docs/reference/json-schemas.md— add annotated CRAP schema sectiondocs/reference/cli/schema.md— addcrapto argument list and examplesRisks
Score/Summaryrequires a schema update--baselineoutput fails validationNote on
reportoutputPer the review council analysis on #118,
gaze report --format=jsonshould NOT get a schema. It is explicitly documented as "an internal format" (json-schemas.md:352), usesjson.RawMessagefields, and CI integration uses threshold flags rather than schema validation.