Skip to content

Complete JSON Schema parity and safe reconstruction - #490

Merged
binaryfire merged 11 commits into
0.4from
audit/json-schema-correctness-parity
Aug 8, 2026
Merged

Complete JSON Schema parity and safe reconstruction#490
binaryfire merged 11 commits into
0.4from
audit/json-schema-correctness-parity

Conversation

@binaryfire

@binaryfire binaryfire commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

This completes the JSON Schema correctness and parity work. It adds first-party union and anyOf builders, introduces bounded reconstruction through JsonSchema::fromArray(), and fixes serializer behavior that could lose or change valid schema meaning.

The result is a round-trippable fluent API for the subset Hypervel can represent. Unsupported or ambiguous input now fails directly instead of being weakened silently.

What changed

  • Add union() and anyOf() to the JSON Schema factory and public contract.
  • Add JsonSchema::fromArray() for the supported JSON Schema 2020-12 subset.
  • Resolve local JSON Pointer references with per-operation caching, bounded reference depth, and bounded aggregate expansion.
  • Preserve explicit null defaults separately from an unset default.
  • Make required, nullable, and unique constraints reversible.
  • Preserve empty enums, object-shaped defaults, numeric property maps, and permissive array forms.
  • Validate the final union and anyOf shape after nullability is applied.
  • Preserve exact nullable composition semantics, including oneOf match cardinality and branch-local enum ownership.
  • Reject circular, remote, malformed, unsupported, or lossy reconstruction paths with direct errors.
  • Publish a first-party guide covering construction, serialization, reconstruction, references, supported forms, and failure behavior.

Design

Reconstruction is intentionally strict. Recognized validation keywords are either represented faithfully or rejected; they are never discarded. Local reference resolution is iterative and scoped to a single fromArray() call, so it adds no shared worker state or request hot-path work.

Nullable composition is handled according to its actual validation semantics. oneOf inputs must retain exactly one null match. anyOf may retain overlapping null branches, and enums owned by a non-null branch remain on that branch rather than being hoisted across the composition.

The public changes are additive. Existing builders keep their current behavior, while union, anyOf, explicit null defaults, and reconstruction become available through the same fluent conventions as the rest of the package.

Validation

  • Ran the complete formatter, static analysis, and parallel test gate.
  • Exercised all supported schema types, nested and referenced schemas, exact round trips, malformed inputs, unsupported assertions, integer bounds, resource limits, and nullable composition counterfactuals.
  • Verified stable reconstruction and serialization across the supported schema matrix.

For more details, see: docs/plans/2026-08-07-2015-json-schema-correctness-current-parity-and-bounded-reconstruction.md

Summary by CodeRabbit

  • New Features

    • Added support for JSON Schema unions and anyOf compositions.
    • Added conversion from supported JSON Schema documents back into schema types, including references, nullable forms, constraints, defaults, and validation.
    • Improved serialization of unions, nullable values, object shapes, and explicit null defaults.
    • Added array uniqueness configuration.
  • Documentation

    • Added comprehensive JSON Schema usage and compatibility documentation.
    • Added JSON Schema navigation links.
  • Bug Fixes

    • Invalid, unsupported, circular, or lossy schemas now fail clearly instead of producing misleading results.

Add the first user-facing guide for building, serializing, and reconstructing JSON schemas.

Cover primitive and structured schemas, metadata, required and nullable properties, unions, any-of schemas, local references, and the supported reconstruction subset.
Preserve explicit null defaults independently from unset defaults, make required, nullable, and unique flags reversible, and retain valid empty enum values.

Emit numeric property maps and list-shaped object defaults as JSON objects, validate final union and any-of output after nullability is applied, and preserve JSON encoding failures with JSON_THROW_ON_ERROR. Add focused regression coverage for every corrected type and wire shape.
Expose multi-type unions and constrained any-of alternatives through the JSON Schema factory and contract using concrete, Laravel-style return types.

Normalize null union members into nullability, reject unsupported or non-string members without coercion, preserve member order, and support shared metadata and explicit defaults. Cover direct construction, closures, nullability, failure paths, and round trips.
Add JsonSchema::fromArray() and rebuild the supported JSON Schema 2020-12 subset without silently weakening recognized validation rules or malformed input.

Resolve local references iteratively with per-operation caching, a bounded active path, and a bounded aggregate expansion count. Preserve representable null, composition, enum, default, object-map, and permissive-items forms while rejecting circular, remote, lossy, or structurally conflicting schemas.

Exercise every supported type, nested and referenced schemas, exact round trips, resource bounds, invalid keyword values, unsupported assertions, integer limits, and composition failure paths.
Add the JSON Schema guide to the framework documentation navigation and link the package README to the canonical user documentation.

Record the public differences from Laravel that developers must account for, including explicit null defaults, sum-type defaults, strict reconstruction failures, supported null and items forms, and bounded local reference expansion.
Mark the package complete in the framework audit checklist and route future readers to the dedicated JSON Schema plan and ledger entry.

Record the accepted findings, rejected speculative mechanisms, lifecycle and performance assessment, regression coverage, upstream handoff, validation results, and final no-debt disposition.
Capture the verified Laravel parity surface, serializer and reconstruction defects, approved API improvements, bounded-reference design, and explicit anti-overengineering constraints.

Describe the final implementation by owning boundary, include representative code, define the regression and full-gate validation plan, and preserve the completed audit decisions needed for future maintenance.
Rewrite the guide in the simple, direct prose used by first-party Laravel documentation while preserving the original baseline in commit history.

Clarify reversible constraints, supported union members, serialization failures, reference limits, nullable one-of reconstruction, permissive array forms, malformed inputs, unsupported keywords, and valid schema forms the fluent builder cannot preserve.
…ectness-parity

# Conflicts:
#	docs/plans/2026-07-12-0915-framework-coroutine-state-lifecycle-audit-ledger.md
…ectness-parity

# Conflicts:
#	docs/plans/2026-07-12-0900-framework-coroutine-state-lifecycle-audit.md
#	docs/plans/2026-07-12-0915-framework-coroutine-state-lifecycle-audit-ledger.md
Reject nullable oneOf collapses when more than one branch can match null, including duplicate and reference-resolved null branches. Keep branch-local enums scoped inside nullable anyOf compositions and reject the corresponding oneOf form when flattening would change its meaning.

Add counterfactual coverage for exact oneOf cardinality, deliberate anyOf overlap, enum ownership, references, structural siblings, annotations, and existing conflict diagnostics. Clarify the supported reconstruction boundary in the canonical guide and keep the package README limited to genuine additive API differences.

Record the two upstream reconstruction defects under their durable audit findings. The checks remain bounded to explicit fromArray calls and add no shared state or request hot-path work.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 91ab98e3-a4c9-41f6-b66d-f242a5003aa2

📥 Commits

Reviewing files that changed from the base of the PR and between 65ce5f1 and bf78c85.

📒 Files selected for processing (31)
  • docs/plans/2026-07-12-0900-framework-coroutine-state-lifecycle-audit.md
  • docs/plans/2026-07-12-0915-framework-coroutine-state-lifecycle-audit-ledger.md
  • docs/plans/2026-08-07-2015-json-schema-correctness-current-parity-and-bounded-reconstruction.md
  • src/boost/docs/documentation.md
  • src/boost/docs/json-schema.md
  • src/contracts/src/JsonSchema/JsonSchema.php
  • src/json-schema/README.md
  • src/json-schema/src/Deserializer.php
  • src/json-schema/src/JsonSchema.php
  • src/json-schema/src/JsonSchemaTypeFactory.php
  • src/json-schema/src/Serializer.php
  • src/json-schema/src/Types/AnyOfType.php
  • src/json-schema/src/Types/ArrayType.php
  • src/json-schema/src/Types/BooleanType.php
  • src/json-schema/src/Types/IntegerType.php
  • src/json-schema/src/Types/NumberType.php
  • src/json-schema/src/Types/ObjectType.php
  • src/json-schema/src/Types/StringType.php
  • src/json-schema/src/Types/Type.php
  • src/json-schema/src/Types/UnionType.php
  • tests/JsonSchema/AnyOfTypeTest.php
  • tests/JsonSchema/ArrayTypeTest.php
  • tests/JsonSchema/BooleanTypeTest.php
  • tests/JsonSchema/DeserializerTest.php
  • tests/JsonSchema/IntegerTypeTest.php
  • tests/JsonSchema/NumberTypeTest.php
  • tests/JsonSchema/ObjectTypeTest.php
  • tests/JsonSchema/SerializerTest.php
  • tests/JsonSchema/StringTypeTest.php
  • tests/JsonSchema/TypeTest.php
  • tests/JsonSchema/UnionTypeTest.php

📝 Walkthrough

Walkthrough

The JSON Schema package adds union and any-of APIs, bounded schema reconstruction, stricter serialization, explicit default tracking, object-shape normalization, documentation, audit records, and extensive regression tests.

Changes

JSON Schema correctness

Layer / File(s) Summary
Schema APIs and type model
src/contracts/src/JsonSchema/JsonSchema.php, src/json-schema/src/JsonSchema.php, src/json-schema/src/Types/*, tests/JsonSchema/*TypeTest.php
Adds union and any-of types and factories. Tracks explicit defaults, nullable values, array uniqueness, and encoding failures.
Bounded schema deserialization
src/json-schema/src/Deserializer.php, tests/JsonSchema/DeserializerTest.php
Reconstructs supported schemas, resolves local references with depth and expansion limits, and rejects malformed, unsupported, circular, or conflicting schemas.
Schema serialization and JSON shape
src/json-schema/src/Serializer.php, tests/JsonSchema/ObjectTypeTest.php, tests/JsonSchema/SerializerTest.php
Serializes compositions, nullable types, defaults, required keys, and JSON object-shaped property maps.
Documentation and audit records
src/boost/docs/*, src/json-schema/README.md, docs/plans/*
Documents the supported API, reconstruction rules, limits, errors, Laravel differences, and completed audit status.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JsonSchema
  participant Deserializer
  participant ReferenceResolver
  participant Type
  JsonSchema->>Deserializer: fromArray(schema)
  Deserializer->>ReferenceResolver: resolve local $ref
  ReferenceResolver-->>Deserializer: bounded schema
  Deserializer->>Type: construct validated type
  Type-->>JsonSchema: reconstructed Type
Loading

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch audit/json-schema-correctness-parity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@binaryfire
binaryfire merged commit f467fc7 into 0.4 Aug 8, 2026
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant