feat(swift_core): Establish JSON identity routing and evaluation protocols#1720
Open
pinieb wants to merge 20 commits into
Open
feat(swift_core): Establish JSON identity routing and evaluation protocols#1720pinieb wants to merge 20 commits into
pinieb wants to merge 20 commits into
Conversation
This change establishes the foundational infrastructure for Swift libraries in the A2UI monorepo. There is just enough code (JSONValue.swift and its tests) to standup a SwiftPM library and get CI up and running.
Every node in a compiled JSON Schema AST must have a deterministic identity to allow for $ref resolution and accurate error reporting. This identity is a combination of a Base URI and a JSON Pointer (RFC 6901). This change introduces the mechanisms to do this.
…xt management - Add `ValidationContext` and `ValidatorConfiguration` to safely pass execution state (like max depth limits) down the AST without mutation. - Add `ValidationResult` struct designed to support the 2020-12 hierarchical output format, tracking errors and annotations. - Define the `KeywordEvaluator` protocol to standardize keyword execution. - Implement the `SchemaNode` executable AST struct with logic to aggregate results, errors, and annotations from multiple evaluators. - Add test coverage for recursion depth limits and result aggregation.
Contributor
There was a problem hiding this comment.
Code Review
This pull request sets up the A2UISwiftCore package and implements the core types for the generic JSONSchema validator target, including JSONValue, JSONPointer, SchemaIdentity, and SchemaNode, along with comprehensive unit tests and documentation. The review feedback highlights several key improvements: making the JSONPointer string initializer failable to handle malformed paths safely, conforming both JSONPointer and SchemaIdentity to Hashable for collection and dictionary compatibility, normalizing baseURI in SchemaIdentity to prevent double-fragment URIs, and ensuring compliance with the JSON Schema Draft 2020-12 specification by discarding annotations when validation fails.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Pete Biencourt <pinieb@users.noreply.github.com>
…eb/a2ui into swift-json-schema-protocols
# Conflicts: # Package.swift # renderers/swift_core/AGENTS.md # swift/core/CODING_STANDARDS.md # swift/core/JSONSchema/README.md # swift/core/JSONSchema/Sources/JSONPointer.swift # swift/core/JSONSchema/Sources/JSONValue.swift # swift/core/JSONSchema/Sources/KeywordEvaluator.swift # swift/core/JSONSchema/Sources/SchemaIdentity.swift # swift/core/JSONSchema/Sources/SchemaNode.swift # swift/core/JSONSchema/Sources/SchemaRegistry.swift # swift/core/JSONSchema/Sources/ValidationContext.swift # swift/core/JSONSchema/Sources/ValidationError.swift # swift/core/JSONSchema/Sources/ValidationResult.swift # swift/core/JSONSchema/Sources/ValidatorConfiguration.swift # swift/core/JSONSchema/Tests/ExecutionContractsTests.swift # swift/core/JSONSchema/Tests/JSONValueTests.swift # swift/core/JSONSchema/Tests/SchemaIdentityTests.swift # swift/core/README.md
…eb/a2ui into swift-json-schema-protocols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Overview
This PR establishes the foundational skeleton for the JSON Schema evaluation engine. It introduces the core data structures needed to deterministically identify nodes in the schema tree and defines the strict execution contracts required to safely evaluate JSON instances against those nodes.
By separating identity resolution from execution state, this PR paves the way for the
SchemaCompilerand the implementation of specific validation keywords without risking tight coupling or infinite recursion loops.Key Additions
1. Identity & Routing (RFC 6901)
JSONPointer: Implemented a robust path management struct fully compliant with RFC 6901, including proper escaping and unescaping of~0and~1characters.SchemaIdentity: Created a deterministic identity pairing a Base URI with a JSON Pointer. Crucially, this includes theupdatingBaseURIlogic necessary to intercept$idkeywords, allowing schemas to safely reset their resolution scope and pointer paths during compilation.2. Execution Contracts
KeywordEvaluator: Defined the primary protocol that all future validators, applicators, and annotators will conform to.SchemaNode: Implemented the compiled AST node representation. It holds an array ofKeywordEvaluators and handles the aggregation of errors and annotations during evaluation.ValidationResult: Designed to fully support the 2020-12 hierarchical/verbose output format, trackingisValid, errors, annotations, and deeply nested child results.3. Context & State Management
ValidationContext: Introduced the immutable state container passed down during tree traversal.ValidatorConfiguration: Added standard user configurations, includingmaxEvaluationDepthto defend against stack overflows from infinitely recursive malicious schemas.Technical Notes
ValidationContext.passingDown(toInstanceKey:)actively tracks execution depth and will throw a hard error if the configured limit is breached.Testing
$id).SchemaNodesuccessfully aggregates multiple keyword results (combining discrete annotations and errors into a singleValidationResult).Pre-launch Checklist
For this PR:
run_tests.shfor Swift tests