feat(swift_core): implement SchemaRegistry and KeywordRegistry#1734
feat(swift_core): implement SchemaRegistry and KeywordRegistry#1734pinieb wants to merge 27 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.
…egistry - Add `SchemaRegistry` as a shared reference type to cache compiled `SchemaNode`s, enabling synchronous `$ref` resolution and preventing infinite CoW loops during deep evaluation. - Add `KeywordRegistry` and `EvaluatorFactory` to decouple keyword parsing from the core engine, allowing runtime extensibility. - Stub `SchemaCompiler` to resolve dependency graph for applicators. - Add test coverage for node caching and custom keyword injection.
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
…gement # Conflicts: # swift/core/JSONSchema/Sources/KeywordRegistry.swift # swift/core/JSONSchema/Sources/SchemaCompiler.swift # swift/core/JSONSchema/Tests/KeywordRegistryTests.swift # swift/core/JSONSchema/Tests/SchemaRegistryTests.swift
There was a problem hiding this comment.
Code Review
This pull request introduces the A2UISwiftCore package, which implements a generic JSON Schema Draft 2020-12 validator and DSL builder in Swift, along with corresponding unit tests, coding standards, and formatting scripts. The code review feedback highlights several improvement opportunities: normalizing URI lookups in SchemaRegistry to handle trailing # consistently, resolving a 100-character line limit violation in SchemaIdentity.swift, simplifying redundant suffix checks in SchemaIdentity initialization, and safely failing JSONPointer initialization if percent decoding 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
jacobsimionato
left a comment
There was a problem hiding this comment.
Hey I can't remember if I asked this before, but did you consider using an existing Swift JSON schema library? Gemini tells me that this one is well-regarded: https://github.com/ajevans99/swift-json-schema
I know that would require importing an existing library to Google's monorepo, but it does mean less code to own for us. For other languages, we have generally used existing libraries.
It might be easy enough to migrate later if we want to, though?
Otherwise, this looks good to me though, though I didn't pick over it too closely seeing as I believe the JSON schema specification provides a lot of structure. I added Greg to take a look, because he created an equivalent library for the Dart ecosystem.
Description
SchemaRegistryas a shared reference type to cache compiledSchemaNodes, enabling synchronous$refresolution and preventinginfinite CoW loops during deep evaluation.
KeywordRegistryandEvaluatorFactoryto decouple keywordparsing from the core engine, allowing runtime extensibility.
SchemaCompilerto resolve dependency graph for applicators.Pre-launch Checklist
For this PR:
run_tests.shfor Swift.If you need help, consider asking for advice on the discussion board.