You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Make the JSON type schema match the JSON that the encoder writes - #2620
The JSON type schema now moves embedded struct fields up into the parent, skips json:"-" fields, and writes json or utf8 for a type with its own marshaller unless its json tags describe the output, as the encoder does.
Use map-key encoding rules when classifying schema keys
transformers/struct.go:355
Map keys are not encoded through json.Marshaler; encoding/json uses native string/integer formatting or encoding.TextMarshaler. Routing a key through the value-oriented helper means a comparable key type that implements both interfaces is classified as "json", although the encoder invokes MarshalText and writes string keys. Handle map-key method selection separately so the schema matches the stored object.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Amazing work! The flattening of embedded structs and the json:"-" fix are correct, for example for k8s pod volumes and probes, stripe and aws.
I ran an audit of this PR on 108 source plugins. For each plugin, I built all tables before and after the change and compared each JSON type schema with the keys that json.Marshal actually writes (types filled with faker data).
Results (8,141 JSON columns in the 41 plugins that change):
Problem: 472 columns lose correct detail and become "json". Most generated API clients (Google APIs, OpenAPI Generator, oapi-codegen, auth0) have a MarshalJSON that writes the same keys as the json tags. Their old schema was correct, except for a "" key from json:"-" fields.
Performance:jsonSchemaFields runs again for each struct at each depth. On github, table init goes from 84ms to 165ms and allocations from 94MB to 287MB. On stripe, it goes from 194ms to 596ms.
A type with MarshalJSON keeps the schema of its tagged fields.
It uses "json" only when it has no json tags, or when it hides a struct variant in an exported json:"-" field (for example stripe PaymentSource.Card).
Untagged fields of such types are skipped, for example AdditionalProperties.
The field lookup is cached per type. github goes to 72ms/88MB, stripe to 78ms/98MB.
With #2628, only 2 columns lose detail: jira Unknowns, 3 of 710 keys. The extra 44 columns with wrong keys are faker artifacts (empty omitempty fields), and these keys were in the schema before this PR too.
Can you review #2628 and merge it into this branch if it looks good?
The cause is faker, not the schema. For example, datadog image_digest is a datadog.NullableString, and MarshalJSON writes it only when the unexported isSet flag is true. Faker cannot set unexported fields, so the key is missing from the test value, but real API data includes it. The okta profile fields look like the same pattern, and the deep bitbucket, github and gitlab paths look like faker depth limits.
So #2628 adds no new wrong keys and keeps the detail.
…eir json tags (#2628)
Types with their own `MarshalJSON` keep the schema of their tagged
fields unless they have no `json` tags or hide a struct variant in a
`json:"-"` field, and the field lookup is now cached per type.
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
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
The JSON type schema now moves embedded struct fields up into the parent, skips
json:"-"fields, and writesjsonorutf8for a type with its own marshaller unless itsjsontags describe the output, as the encoder does.Fixes https://linear.app/env-zero/issue/ATH-913