fix(analyzer): allOf entries that redeclare a property lost it on the wire - #121
Merged
Conversation
… wire allOf composes one value, so entries may declare the same property, and each declaration became a field. Two fields at one depth carrying one JSON tag is not untidy, it is silent: encoding/json ignores both, so the property stops decoding and stops marshaling while the struct still looks right. GitHub's webhook-fork.forkee composes two inline objects, the second refining 78 of the first's 90 properties. Its client compiled and go vet reported 247 duplicate tags. A property is one field now, and requirements are read from every entry before any field is built, so one required by a later entry is required by the struct rather than depending on which entry declared it first. A property beside an embedded type is untouched: those live at different depths, where Go shadows one with the other and the tags do not collide.
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.
Closes #120. Found by the corpus test from #119, which vets the generated package rather than only building it.
allOfcomposes one value, so entries may declare the same property. Each declaration became a field:The package compiles.
encoding/jsonresolves two fields at one depth carrying one tag by ignoring both, soallow_forkingstopped decoding and stopped marshaling while the struct still looked right. A build-only gate cannot see it, which is why #119 addedgo vetto the corpus test and why this turned up the same day.GitHub's
webhook-fork.forkeeis the case: two inline objects, the second refining 78 of the first's 90 properties.Fix
allOfmeans.Worth noting the history: before #96 fixed field-name collisions, this shape failed to compile. That was louder, and in one narrow sense better than a struct that builds and drops data.
Verification
Tests
internal/analyzer/schemas_allof_property_test.go: a property two entries declare is one field, required because one entry requires it, and a property beside an embed is kept.testdata/combinations.yamlgrows the shape, so the corpus covers it.gofmt,golangci-lint,go vet ./..., andgo test ./...pass.