Skip to content

feat(swift_core): implement SchemaRegistry and KeywordRegistry#1734

Draft
pinieb wants to merge 27 commits into
a2ui-project:mainfrom
pinieb:swift-json-state-management
Draft

feat(swift_core): implement SchemaRegistry and KeywordRegistry#1734
pinieb wants to merge 27 commits into
a2ui-project:mainfrom
pinieb:swift-json-state-management

Conversation

@pinieb

@pinieb pinieb commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Add SchemaRegistry as a shared reference type to cache compiled
    SchemaNodes, 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.

Pre-launch Checklist

For this PR:

  • I have added updates to the CHANGELOG.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on fork, I have verified that scripts/e2e_test.sh passes.
    • Used run_tests.sh for Swift.

If you need help, consider asking for advice on the discussion board.

pinieb and others added 21 commits June 21, 2026 09:20
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>
# 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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread swift/core/JSONSchema/Sources/SchemaRegistry.swift
Comment thread swift/core/JSONSchema/Sources/SchemaIdentity.swift Outdated
Comment thread swift/core/JSONSchema/Sources/SchemaIdentity.swift Outdated
Comment thread swift/core/JSONSchema/Sources/SchemaIdentity.swift Outdated
Comment thread swift/core/JSONSchema/Sources/JSONPointer.swift
pinieb and others added 6 commits June 23, 2026 14:13
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>

@jacobsimionato jacobsimionato left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants