Skip to content

feat: schema merging across endpoint observations (GLA-47)#7

Merged
paoloanzn merged 1 commit intomainfrom
paolo/gla-47-schema-merging
Mar 7, 2026
Merged

feat: schema merging across endpoint observations (GLA-47)#7
paoloanzn merged 1 commit intomainfrom
paolo/gla-47-schema-merging

Conversation

@paoloanzn
Copy link
Contributor

Summary

  • Adds schema-merger.js module that merges per-request schemas into a single enriched schema when the same endpoint is observed multiple times
  • Header merging: unions all header fields across observations, unifies value types into union strings (e.g. string | integer), preserves isAuth if any observation flagged it, marks headers absent from some observations as optional, tracks seenCount
  • Body merging: uses schema-inferrer.unifySchemas for recursive structural merge — conflicting types become mixed with variants, newly seen fields marked optional, array item schemas unified
  • Observation tracking: each endpoint in the export now includes observationCount and mergedSchema instead of just requestCount, giving downstream consumers confidence proportional to sample size

Test plan

  • Capture multiple requests to the same endpoint (e.g. GET /api/users/123 and GET /api/users/456) — verify they group into one endpoint with observationCount: 2
  • Verify mergedSchema in exported JSON contains unified field types across observations
  • Test with responses where a field is null in one observation and string in another — merged schema should show mixed type with ["null", "string"] variants
  • Test with responses where one observation has an extra field — merged schema should mark it optional: true
  • Test with requests where some have an Authorization header and some don't — merged header schema should have isAuth: true and optional: true
  • Export snapshot JSON and verify each endpoint entry has observationCount and mergedSchema

🤖 Generated with Claude Code

Add schema-merger.js that merges per-request schemas into a single
enriched schema when the same endpoint is observed multiple times.

Header merging: unions header fields across observations, unifies
value types into union strings (e.g. "string | integer"), preserves
isAuth if any observation had it, marks headers not seen in every
observation as optional, and tracks seenCount per header.

Body merging: delegates to schema-inferrer's unifySchemas for
recursive structural merging — conflicting field types become mixed
with variants, fields absent in some observations are marked
optional, and array item schemas are unified across all elements.

Endpoint export now includes observationCount and mergedSchema
per endpoint group instead of the previous requestCount, giving
downstream consumers a single enriched schema with confidence
proportional to observations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@linear
Copy link

linear bot commented Mar 7, 2026

GLA-47 Schema merging

When the same endpoint is observed again, merge the new schema into the existing one rather than overwriting.

  • Union types when a field type conflicts across observations (e.g. null + stringstring | null)
  • Add newly seen fields as optional
  • Confidence increases with each observation (track how many times each endpoint was seen)

Done when multiple observations of the same endpoint produce a single enriched schema.

@paoloanzn paoloanzn merged commit 2f81661 into main Mar 7, 2026
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.

1 participant