You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clean and targeted fix for swagger generation of interface{} array types (fixes #5426).
Problem:itemFromGoType() had no case for apiSpec.InterfaceType, causing the function to return nil for []interface{} fields. This meant the generated Swagger had items: null, which is invalid per OpenAPI 2.0 spec.
Changes:
itemFromGoType — Added case apiSpec.InterfaceType that returns {type: "object"}. This is the correct representation: interface{} can be any JSON value, and object is the closest Swagger 2.0 approximation.
typeFromGoType / sampleTypeFromGoType — Added apiSpec.InterfaceType to the struct/map case, so these two helpers also return "object" for interface{} values. This ensures consistency across all three type-mapping functions.
Test:TestNestedArrayInterfaceItems validates a [][]interface{} field, confirming the nested array has correct items → items → {type: object} chain.
One note: Using "object" for interface{} is a pragmatic choice — the technically correct Swagger 2.0 representation would be to omit type constraints (empty schema {}), which matches any JSON type. However, "object" is widely accepted and consistent with how other generators handle this case.
LGTM — the fix is minimal, correct, and well-tested.
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
area/goctlCategorizes issue or PR as related to goctl.kind/bugSomething isn't working
2 participants
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 #5426
Summary
interface{}types to Swagger object schemas when building array item schemas.[][]interface{}so generated Swagger 2.0 includes the required nesteditemsfield.Test Plan
GOWORK=/tmp/go-zero-swagger-work/go.work GOCACHE=/tmp/go-build GOPROXY=https://goproxy.cn,direct go test ./api/swagger