Skip to content

fix(v3): build swaggertype array overrides with items, not additional…#2200

Open
kklem0 wants to merge 1 commit into
swaggo:v2from
sssf-code:fix-v3-custom-array-items
Open

fix(v3): build swaggertype array overrides with items, not additional…#2200
kklem0 wants to merge 1 commit into
swaggo:v2from
sssf-code:fix-v3-custom-array-items

Conversation

@kklem0

@kklem0 kklem0 commented Jul 19, 2026

Copy link
Copy Markdown

Fixes the v3 half of the swaggertype:"array,..." override (see umbrella issue).

BuildCustomSchemaV3's ARRAY case stored the element schema in additionalProperties (a map keyword) and left Items nil — the line was marked // TODO: check if this is correct. Any field using an array swaggertype override then panicked in complementSchema dereferencing schema.Items.Schema.Spec:

AuthorIDs []pgtype.Int4 `json:"author_ids" swaggertype:"array,integer"`
panic: runtime error: invalid memory address or nil pointer dereference
  github.com/swaggo/swag/v2.(*tagBaseFieldParserV3).complementSchema

This mirrors how parseTypeExprV3 builds schemas for ordinary Go slices (Items = spec.NewBoolOrSchema(false, itemSchema)).

After the fix the override renders as expected:

{"type": "array", "items": {"type": "integer"}}

Adds TestBuildCustomSchemaV3 covering array/object/primitive/error cases. Validated on a production codebase (126 operations): generation completes and array overrides render correctly.

…Properties

BuildCustomSchemaV3's ARRAY case stored the element schema in
additionalProperties (a map keyword) and left Items nil, so any field
using a `swaggertype:"array,<type>"` override produced an invalid array
schema and complementSchema panicked dereferencing
schema.Items.Schema.Spec (field_parserv3.go).

Mirror parseTypeExprV3's handling of ordinary slices and put the element
schema in Items. Resolves the TODO that marked this line.

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