feat(schema,config): pluggable parser registry (#129)#201
Merged
Conversation
Closes #129. Extracts the schema and config YAML parsers behind a small Parser interface + package-level registry. Each spec version is now a single sibling file (e.g. parser_v1.go) that declares a parser struct and registers it via init(). Adding v2 in the future means landing one new file — the existing v1 path stays untouched, and nothing else in the codebase changes. The service layer dispatches through the registry on ImportSchema / ImportConfig (peeks `spec_version:` from the YAML header, looks up the registered parser, delegates) and on ExportSchema / ExportConfig (uses the request's optional `spec_version` field, defaulting to the highest registered version when absent). Layer-2 semantic checks (referential integrity, prefix-overlap, dependentRequired field-existence, range sanity) run on the proto value AFTER dispatch — they're version-agnostic and shared across all parsers. Unknown spec_version values produce a clear InvalidArgument error listing the supported versions. Wire surface: - Adds optional `spec_version` field to ExportSchemaRequest (proto field 3) and ExportConfigRequest (proto field 3). Additive change — no break for existing clients. - New entry points: schema.Dispatch, schema.MarshalSchemaAt, schema.SupportedVersions, schema.LatestVersion (and symmetric for config — DispatchImport / MarshalConfigAt). All exported from the parent package; v1 file uses package-private helpers. Test coverage: - New parser_test.go in both packages: SupportedVersions / LatestVersion / Dispatch (route, missing spec_version, unknown version, malformed YAML) / MarshalSchemaAt (default, explicit version, unknown version) / round-trip (Dispatch → Marshal → Dispatch preserves all fields, including dependentRequired and validations). - Existing yaml_test.go suites unchanged — parser_v1 is a thin wrapper over the same underlying functions. Docs: - meta-schema.md gains a "Multi-version evolution" section describing the plug-in pattern and the spec_version request field. - schema-spec.md updated with the registry shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for your first pull request! We appreciate the contribution. Before review, please make sure:
|
The new parser_test.go suites in internal/schema/ and internal/config/ push internal coverage from 80.0% → 81.9%. Ratchet the threshold so future regressions don't slide silently back below the new bar. Same for sdk/adminclient (97.2 → 97.6) and sdk/tools (95.8 → 96.1) — small incidental upticks from indirect coverage of the new registry methods. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #129. Final cross-cutting issue in the Schema Spec v0.1.0 milestone.
Summary
Extracts the schema and config YAML parsers behind a small `Parser` interface + package-level registry. Each spec version is now a single sibling file (e.g. `parser_v1.go`) that declares a parser struct and registers it via `init()`. Adding v2 in the future means landing one new file — the existing v1 path stays untouched, and nothing else in the codebase changes.
Design
```go
type Parser interface {
SpecVersion() string
Parse(data []byte) (*pb.Schema, error)
Marshal(s *pb.Schema) ([]byte, error)
}
func Register(p Parser) // called from each parser's init()
func Dispatch(data []byte) (*pb.Schema, error) // routes by spec_version
func MarshalSchemaAt(s *pb.Schema, version string) (...) // emits in chosen version
func SupportedVersions() []string // surfaced in errors
func LatestVersion() string // default for export
```
(Symmetric in `internal/config/` — `DispatchImport` carries the schema's `fieldTypes` since the config parser needs them for type-aware coercion, and returns a `ParsedImport` struct so the service layer can pick up the YAML's `description:` for audit purposes.)
Layer split
redirect_to,dependentRequiredfield existence), prefix-overlap rejection, range sanity, runtime cross-field rules (dependentRequired).The dispatch point sits between the two — `Dispatch` returns a `*pb.Schema`, then service.go runs the layer-2 checks on that proto value, identical regardless of which version produced it.
Wire surface
Test coverage
Docs
Test plan