Repository navigation
feat(common-avro,common-json,common-protobuf): retain and expose field-level schema annotations - #2368
Conversation
|
Pushed a second commit filling out
Full Generated by Claude Code |
|
Third commit: ported Not a literal copy of
Both needed something JSON Schema's port didn't: an identity-based cycle guard. Unlike JSON Schema (safe only because Full Generated by Claude Code |
|
Correction to the two comments above: both quote or reference things that don't belong in this thread — a literal For the record, what actually shipped in the two commits those comments describe, without the extraneous framing:
All test/build claims in the two prior comments (test counts, Generated by Claude Code |
…d-level schema annotations Part 1 of #2302 -- codec-level retention and exposure of field-level schema annotations. Today all three codecs silently discard any annotation they don't recognize as a standard keyword; this retains them and exposes them in the form natural to each format, read from the field object only (never inherited from the field's type or a named type reference). Issue #2302 bundles two very differently-sized pieces of work: (a) codec-level annotation retention, and (b) a matcher/action config DSL with YAML schema, path-pattern matching, and per-model evaluation across model-avro/model-json/model-protobuf. (b) has no existing precedent in this codebase and is greenfield design in its own right; this change delivers (a) as a complete, tested, mergeable unit, and leaves (b) for focused follow-up work. common-avro: - AvroField.attribute(String) reads an arbitrary key from the field's own JSON object, returned as JsonValue; null when absent - AvroType.matchingPaths(Predicate<AvroField>) walks record fields, array items(), map values(), and union branches(), returning the path of every field a predicate matches, in declaration order. A match does not stop descent. Guards against infinite recursion on self-referential record types (already documented as legal by AvroType's own class javadoc) with an identity-based "on this recursion path" Set common-json: - JsonSchema.property(String) navigates to a property's compiled sub-schema (JSON Schema has no separate field object), and JsonSchema.attribute(String) reads an arbitrary key declared directly on a schema node -- not inherited through $ref - JsonSchema.matchingPaths(Predicate<JsonSchema>) walks the compiled schema tree (properties, single-schema items, allOf/anyOf/oneOf/ if/then/else) and returns the RFC 6901 pointers of every node a predicate matches. $ref, patternProperties, and tuple items are not expanded - retainedPaths() is reimplemented on the same walker, operating on the already-compiled schema tree instead of a separate JsonSchemaPaths utility that re-parsed the schema text into a second, parallel tree. This also fixes a latent inconsistency where pre-2019-09 $ref siblings were walked even though the validator itself ignores them for those drafts. JsonSchemaPaths/JsonSchemaPathsTest deleted outright -- their only call site was retainedPaths() itself, and its test coverage is preserved in JsonSchemaRetainedPathsTest, now driven through the public JsonSchema API common-protobuf: - New ProtobufConstant sealed type (Identifier/IntegerValue/FloatValue/ TextValue/BooleanValue/MessageValue) plus ProtobufField.option(String), walked directly from the ANTLR parse tree rather than routed through ProtobufJson. Options need no pre-declaration by an imported .proto; message-valued options expose their structure rather than flattened text; string constants are unquoted. Fixes a grammar ambiguity where true/false field-option values parse as a bare fullIdent rather than boolLit (the ident rule folds BOOL_LIT into keywords), which would otherwise have misclassified boolean options as identifiers - ProtobufMessage.matchingPaths(Predicate<ProtobufField>) recurses through composite (message-typed) fields. A repeated composite field gets a synthetic "-" wildcard segment before descending, matching the array-of-objects convention used for Avro/JSON Schema -- except a map field (protobuf desugars maps into a repeated synthetic entry message with named key/value fields) reaches its value type one segment deeper, at .../value/..., since that field is genuinely named in protobuf's own model. Guards against recursive messages the same way AvroType does Full verify (tests + checkstyle + license headers + JaCoCo coverage) green on all three modules; no regressions.
fdb8c6f to
0c58bea
Compare
Description
Part 1 of #2302 — codec-level retention and exposure of field-level schema annotations across
common-avro,common-json, andcommon-protobuf. Today all three codecs silently discard any annotation they don't recognize as a standard keyword; this PR retains them and exposes them in the form natural to each format, read from the field object only (never inherited from the field's type or a named type reference).Scope note: issue #2302 originally bundled two very differently-sized pieces of work: (a) codec-level annotation retention (§1–§3), and (b) a matcher/action config DSL with YAML schema, path-pattern matching, and per-model evaluation across
model-avro/model-json/model-protobuf(§4–§8). (b) had no existing precedent in this codebase — no matcher config of any kind, no Avro path-pointer walker equivalent toJsonSchema.retainedPaths()— it was greenfield design in its own right. This PR delivers (a) as a complete, tested, mergeable unit.Update: (b) was never picked up as a shared oss capability — the SPI issues that once cited #2302 as a blocker (#1681, #1682, #1683) only ever needed the retention/exposure work in this PR, and explicitly left tag-based field selection as "entirely its own design" for whatever extension installs it. The one concrete consumer (zilla-plus's field disclosure feature) built its own per-format matcher config directly rather than depending on a shared primitive. #2302 has been retitled/re-scoped to reflect that this PR is its complete fix, not a partial one.
Changes
common-avro:AvroField.attribute(String)reads an arbitrary key from the field's own JSON object, returned asJsonValue;nullwhen absent.common-json:JsonSchema.property(String)navigates to a property's compiled sub-schema (JSON Schema has no separate field object), andJsonSchema.attribute(String)reads an arbitrary key declared directly on a schema node — not inherited through$ref.JsonSchema.matchingPaths(Predicate)walks the compiled schema tree and returns the RFC 6901 pointers of every node a caller-supplied predicate matches;retainedPaths()is reimplemented on the same walker, replacing the oldJsonSchemaPathsutility (deleted — it re-parsed the schema text into a second, parallel tree).common-protobuf: newProtobufConstantsealed type (Identifier/IntegerValue/FloatValue/TextValue/BooleanValue/MessageValue) plusProtobufField.option(String), walked directly from the ANTLR parse tree rather than routed throughProtobufJson. Options need no pre-declaration by an imported.proto; message-valued options expose their structure rather than flattened text; string constants are unquoted. Along the way this fixes a grammar ambiguity wheretrue/falsefield-option values parse as a barefullIdentrather thanboolLit(theidentrule foldsBOOL_LITintokeywords), which would otherwise have misclassified boolean options as identifiers.common-avro/common-protobuf:AvroType.matchingPaths(Predicate)andProtobufMessage.matchingPaths(Predicate)port the same predicate-driven path-discovery shape, each over the type that actually carries annotations in that format. Both guard against infinite recursion on self-referential schemas with an identity-based "on this recursion path"Set.Test plan
AGENTS.md)./mvnw clean verify -pl runtime/common-avro— tests, checkstyle, license headers, JaCoCo coverage all pass./mvnw clean verify -pl runtime/common-json— same, no regressions./mvnw clean verify -pl runtime/common-protobuf— same, no regressionsAvroField/JsonSchema/ProtobufField/AvroType/ProtobufMessageexist in the codebase that the added methods could breakFixes #2302
Generated by Claude Code