Merge required keys of untagged embedded structs into the parent - #121
Merged
Merged
Conversation
Coverage Report for CI Build 36029644648Coverage decreased (-0.3%) to 57.488%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
seanogdev
marked this pull request as ready for review
September 23, 2026 17:34
rafaeljusto
reviewed
Sep 24, 2026
A count of the embeds that have a key did not use depth or tags. Thus
a key from a shallow field or from a tagged field became optional. Keep
the depth and the tag count for each key, and add an embed key to
required only if encoding/json uses that field. An {omitdoc} field of
the parent now also shadows an embed key.
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.
Changes
requiredkeys of an untagged embedded struct are now required in the parent. Before, only itspropertiesmerged into the parent.{omitdoc}.{required}keys, because encoding/json writes none of its fields when it is nil.infer-requiredoff, so the explicit{required}keys of an embed are now required in the parent.Programkeeps the JSON keys of each struct: smallest depth, field count and tag count. A parent applies the rule from these keys and does not parse its embeds again.Files changed
docparse/find.go:mergeEmbedsand the key helpers, out ofGetReferencedocparse.go:jsonKeysonProgramjsonschema.go: sharedfieldDocfallbackdoc/syntax.markdown: required keys of embedded structstestdata/openapi2/src/embed-required/in.go: value, pointer, clash, depth, tag,{omitdoc}and nested embedstest.conf: comment addedwant.yaml,want3.yaml: expected OpenAPI 2 and 3 outputtestdata/openapi2/src/embed-required-explicit/in.go: explicit{required}in value and pointer embedswant.yaml,want3.yaml: expected output withinfer-requiredoffFocus areas
docparse/find.gorequireduses the encoding/json rule.propertiesstill merge with the first embed winning, so a key that encoding/json drops still shows inproperties.infer-requiredwho put{required}on embed fields.Screenshots