Skip to content

Add JSON schema generation/validation and structured configuration diagnostics#288

Merged
rdeago merged 10 commits into
Tenacom:mainfrom
rdeago:feature/json-schema
May 31, 2026
Merged

Add JSON schema generation/validation and structured configuration diagnostics#288
rdeago merged 10 commits into
Tenacom:mainfrom
rdeago:feature/json-schema

Conversation

@rdeago
Copy link
Copy Markdown
Member

@rdeago rdeago commented May 31, 2026

Summary

Introduces Buildvana.Core.JsonSchema, a model-independent library that generates a JSON Schema (draft 2020-12) from a .NET type and validates a parsed document against it, reporting each failure with a kind, a JSON Pointer, and a 1-based source line/column. The configuration loader (buildvana.json/.jsonc) now uses it, surfacing schema violations as structured BuildDiagnostics that bv renders in canonical file(line,column): error CODE: message form (clickable in VS Code).

The repository-root configuration file remains inert (discovered, parsed, validated, exposed — but no setting affects the build yet), as already noted in the changelog.

What's included

  • Buildvana.Core.JsonSchemaJsonSchemaGenerator (attribute-driven: [Description], [JsonNullable], [JsonAllowedKeys], [JsonSchemaTitle]), JsonSchemaValidator (subset of draft 2020-12: type, enum, properties, required, additionalProperties, items, $ref), and JsonSourceMap (pointer → 1-based line/column over UTF-8). The same JsonSerializerOptions drive generation and deserialization, so the committed schema always matches what the loader accepts.
  • Structured diagnosticsBuildDiagnostic / BuildDiagnosticSeverity and a BuildFailedException.Diagnostics list; bv prints each diagnostic verbatim in compiler format.
  • Configuration — the loader parses to a JsonNode, validates against the generated schema, then deserializes; codes BV1100–BV1105 documented in docs/ToolDiagnostics.md.
  • Tests — new Buildvana.Core.JsonSchema.Tests and Buildvana.Core.Configuration.Tests projects.
  • Regenerated schemas/buildvana.schema.json.

Note: unrelated DotNetConfig restructuring

Commit 4eb1c16 restructures DotNetConfig into per-command invocation config (all/restore/build/test/pack/nugetPush), each with args + env. This is unrelated, preparatory work for the next PR; it landed on this branch and is too late to factor out cleanly, so it rides along here. It only reshapes the (inert) configuration model.

Testing

dotnet build Buildvana.slnx clean (0 warnings); the JsonSchema (22) and Configuration (7) test suites pass.

rdeago and others added 10 commits May 31, 2026 02:59
The BV1100 (invalid JSON) diagnostic computed its column from JsonException.BytePositionInLine, a byte offset, while schema-validation diagnostics report character-based columns via JsonSourceMap. On a line with multi-byte characters before the error the two disagreed, so the clickable file(line,column) link landed past the real position. Convert the byte position to a character column with Encoding.UTF8.GetCharCount.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
JsonSchemaValidationError.DisplayPath was reconstructed from the JSON Pointer after the fact, inferring array-index vs object-key from whether a token was all digits, so an all-digit dictionary key rendered as an array index ([1] instead of .1). Thread a display path alongside the pointer through the validator, where the structural context is known: object members render as .name and array elements as [index], so a numeric object key is never mistaken for an index.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added area:docs [issue/PR] affects documentation (excluding XML documentation that is part of source code). area:code [issue/PR] affects project code (excluding tests). labels May 31, 2026
@rdeago rdeago added the enhancement [issue/PR] requests / implements new or improved functionality. label May 31, 2026
@rdeago
Copy link
Copy Markdown
Member Author

rdeago commented May 31, 2026

This PR has been reviewed locally.

@rdeago rdeago merged commit 11e92a7 into Tenacom:main May 31, 2026
5 of 6 checks passed
@rdeago rdeago deleted the feature/json-schema branch May 31, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:code [issue/PR] affects project code (excluding tests). area:docs [issue/PR] affects documentation (excluding XML documentation that is part of source code). enhancement [issue/PR] requests / implements new or improved functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant