fix(v3): only skip fields with an explicit json:"-", not any missing …#2201
Open
kklem0 wants to merge 1 commit into
Open
fix(v3): only skip fields with an explicit json:"-", not any missing …#2201kklem0 wants to merge 1 commit into
kklem0 wants to merge 1 commit into
Conversation
…json name ShouldSkip treated an empty JsonName() as "skip", which conflates json:"-" with "the field has a struct tag but no json key". Structs tagged only for other encoders (xml, yaml, validate, ...) were silently reduced to empty object schemas, and their nested types disappeared from the spec entirely — encoding/json still serializes such fields under their Go names, and FieldName() already resolves them via the property naming strategy, matching v1 behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes the silent-empty-schema bug for structs tagged only for other encoders (see umbrella issue).
ShouldSkiptreated an emptyJsonName()as "skip this field", which conflates two different situations: an explicitjson:"-"and a field that has a struct tag without anyjson:key (xml/yaml/validate/...). encoding/json still serializes the latter under the Go field name, andFieldName()already resolves such fields via the property naming strategy — but they never got that far, so structs like:were emitted as
{"type": "object"}with no properties and no warning, and every type referenced only through them vanished from the spec (15 schemas in our codebase). swag v1 documents the same struct as{teiHeader, text, xmlname}; this PR restores that behavior by only skipping an explicitjson:"-".Adds
TestShouldSkipV3. Validated on a production codebase: schema count returns to parity with the v1 generator (130/130).