Skip to content

fix(v3): only skip fields with an explicit json:"-", not any missing …#2201

Open
kklem0 wants to merge 1 commit into
swaggo:v2from
sssf-code:fix-v3-skip-only-explicit-json-dash
Open

fix(v3): only skip fields with an explicit json:"-", not any missing …#2201
kklem0 wants to merge 1 commit into
swaggo:v2from
sssf-code:fix-v3-skip-only-explicit-json-dash

Conversation

@kklem0

@kklem0 kklem0 commented Jul 19, 2026

Copy link
Copy Markdown

Fixes the silent-empty-schema bug for structs tagged only for other encoders (see umbrella issue).

ShouldSkip treated an empty JsonName() as "skip this field", which conflates two different situations: an explicit json:"-" and a field that has a struct tag without any json: key (xml/yaml/validate/...). encoding/json still serializes the latter under the Go field name, and FieldName() already resolves such fields via the property naming strategy — but they never got that far, so structs like:

type BookTei struct {
    XMLName   xml.Name  `xml:"http://www.tei-c.org/ns/1.0 TEI"`
    TeiHeader TeiHeader `xml:"teiHeader"`
    Text      TeiText   `xml:"text"`
}

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 explicit json:"-".

Adds TestShouldSkipV3. Validated on a production codebase: schema count returns to parity with the v1 generator (130/130).

…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>
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