Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: json tag make wrong output #1934

Open
haohanyuzmx opened this issue Dec 2, 2024 · 0 comments
Open

V2: json tag make wrong output #1934

haohanyuzmx opened this issue Dec 2, 2024 · 0 comments

Comments

@haohanyuzmx
Copy link

Describe the bug
struct with json tag will different to without

To Reproduce
Steps to reproduce the behavior:

package main

import "github.com/gin-gonic/gin"

//go install github.com/abice/go-enum@latest
//go:generate go-enum --output-suffix _generate.go
//swag i --pd --output ./docs/api --v3.1

// ENUM(a,b,c,d)
type EC string

type Response[t any] struct {
	EC    EC     `json:"ec"`
	Data  t      `json:"data"`
	Error string `json:"error"`
}

// ENUM(aa,bb,cc,dd)
type OtherEnum string

type Complex struct {
	F1 EC          `json:"f_1"`
	F2 []OtherEnum `json:"f_2"`
	F3 []int       `json:"f_3"`
}

// @contact.name   API Support
func main() {
	r := gin.New()
	r.Run()
}

// @Summary      test1
// @Description  test1
// @Produce      json
// @Success      200  {object}  Response[string]
// @Router       /test1 [get]
func test1() {}

// @Summary      test2
// @Description  test2
// @Produce      json
// @Success      200  {object}  Response[[]Complex]
// @Router       /test2 [get]
func test2() {}

this with result

    main.Response-array_main_Complex:
      properties:
        data:
          items:
            $ref: '#/components/schemas/main.Complex'
          type: array
          uniqueItems: false
        ec:
          type: string
          x-enum-varnames:
          - ECA
          - ECB
          - ECC
          - ECD
        error:
          type: string
      type: object

Expected behavior

    main.Response-array_main_Complex:
      properties:
        data:
          items:
            $ref: '#/components/schemas/main.Complex'
          type: array
        ec:
          $ref: '#/components/schemas/main.EC'
        error:
          type: string
      type: object

Your swag version
2.0.0-rc3

Your go version
1.23.2

Desktop (please complete the following information):
macos

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

No branches or pull requests

1 participant