Skip to content

refactor: route HTTP gateway JSON through engine type inference#288

Merged
mosuka merged 1 commit intomainfrom
refactor/gateway-json-type-inference
Apr 25, 2026
Merged

refactor: route HTTP gateway JSON through engine type inference#288
mosuka merged 1 commit intomainfrom
refactor/gateway-json-type-inference

Conversation

@mosuka
Copy link
Copy Markdown
Owner

@mosuka mosuka commented Apr 25, 2026

Summary

  • Route laurus-server HTTP gateway JSON ingestion through laurus::engine::type_inference::infer_from_json so REST inputs follow the same inference rules as schema-less ingestion.
  • Drop the hand-rolled converter (numeric-array → vector, canonical-only geo keys, silent text fallbacks) in favor of the engine helper, which now reaches multi-valued numerics following Add native support for multi-valued numeric fields (Int64Array / Float64Array) #281.
  • Surface inference errors as HTTP 400 with the offending field name instead of quietly text-stringifying the value.

Behavior changes (pre-release, allowed)

Input Before After
[1, 2, 3] VectorValue (legacy) Int64ArrayValue (multi-valued integer)
[1.0, 2.5] VectorValue Float64ArrayValue (multi-valued float)
[] TextValue("[]") NullValue (skipped)
[1, "x"] TextValue("[1,\"x\"]") HTTP 400
{"lat":..., "lon":...} TextValue GeoValue
{"latitude": 200, "longitude": 0} accepted HTTP 400
{"foo":"bar"} TextValue("{...}") HTTP 400

Vector REST ingestion is preserved: declared vector fields keep accepting numeric arrays because coerce_to_vector already handles Int64Array/Float64Array (PR #286).

Implementation

  • laurus-server/src/gateway/convert.rsjson_value_to_proto is now Result<v1::Value, String>, delegating to infer_from_json + data_value_to_proto. json_to_proto_document propagates per-field errors with the field name.
  • laurus-server/src/convert/document.rsdata_value_to_proto / data_value_from_proto made pub so the gateway can lower the inferred DataValue.
  • laurus/src/lib.rs — re-export InferredValue / infer_from_json / infer_option_from_data_value for 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: new "JSON Field Value Inference" section in docs/src/laurus-server/http_gateway.md (+ JA translation).

Closes #282

Test plan

  • cargo fmt --check
  • cargo 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 pass
  • markdownlint-cli2 "docs/src/**/*.md" "docs/ja/src/**/*.md" — 0 errors
  • mdbook build docs && mdbook build docs/ja

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).
@mosuka mosuka merged commit 473e323 into main Apr 25, 2026
22 checks passed
@mosuka mosuka deleted the refactor/gateway-json-type-inference branch April 25, 2026 13:14
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.

Wire JSON-based type inference into the laurus-server gateway

1 participant