refactor: route HTTP gateway JSON through engine type inference#288
Merged
refactor: route HTTP gateway JSON through engine type inference#288
Conversation
The gateway previously used a hand-rolled JSON-to-proto converter that treated all numeric arrays as vectors, only accepted the canonical `latitude`/`longitude` geo keys, and silently text-stringified anything that did not match. With multi-valued numeric support landed (#281), the engine's `infer_from_json` is now production-ready, so route the gateway through it and surface inference errors as HTTP 400 instead of quiet fallbacks. User-visible changes: - Numeric arrays become multi-valued integer/float fields. Vector REST ingest still works because `coerce_to_vector` accepts numeric arrays. - Geo objects accept the `lat`/`lon`/`lng` aliases and reject out-of-range coordinates. - Mixed arrays and non-geo objects return a 400 error citing the offending field name. Documents the new mapping in `docs/src/laurus-server/http_gateway.md` (and the Japanese translation).
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.
Summary
laurus-serverHTTP gateway JSON ingestion throughlaurus::engine::type_inference::infer_from_jsonso REST inputs follow the same inference rules as schema-less ingestion.Behavior changes (pre-release, allowed)
[1, 2, 3]VectorValue(legacy)Int64ArrayValue(multi-valued integer)[1.0, 2.5]VectorValueFloat64ArrayValue(multi-valued float)[]TextValue("[]")NullValue(skipped)[1, "x"]TextValue("[1,\"x\"]"){"lat":..., "lon":...}TextValueGeoValue{"latitude": 200, "longitude": 0}{"foo":"bar"}TextValue("{...}")Vector REST ingestion is preserved: declared vector fields keep accepting numeric arrays because
coerce_to_vectoralready handlesInt64Array/Float64Array(PR #286).Implementation
laurus-server/src/gateway/convert.rs—json_value_to_protois nowResult<v1::Value, String>, delegating toinfer_from_json+data_value_to_proto.json_to_proto_documentpropagates per-field errors with the field name.laurus-server/src/convert/document.rs—data_value_to_proto/data_value_from_protomadepubso the gateway can lower the inferredDataValue.laurus/src/lib.rs— re-exportInferredValue/infer_from_json/infer_option_from_data_valuefor downstream crates.laurus/src/engine/type_inference.rs— drop#![allow(dead_code)]; refresh the doc table to include array → multi-valued numeric mappings (the "not yet supported" note is now stale).docs/src/laurus-server/http_gateway.md(+ JA translation).Closes #282
Test plan
cargo fmt --checkcargo clippy --all-targets --workspace --exclude laurus-ruby -- -D warnings(laurus-ruby skipped, ruby.h env issue, same as PR feat: multi-valued numeric DataValue and schema flag (PR1/2 of #281) #286)cargo test -p laurus-server --lib— 23/23 pass (14 new gateway cases: array roundtrips, geo aliases, range checks, mixed-array error, non-geo object error, document-level field-name error)cargo test -p laurus— 698 unit + integration tests passmarkdownlint-cli2 "docs/src/**/*.md" "docs/ja/src/**/*.md"— 0 errorsmdbook build docs && mdbook build docs/ja