我在 Golang 中使用 swag。我想知道如何在类似的路径中准确选择和使用多个数据类。下面的示例对此进行了准确描述。
我的代码中有3个数据类
1. ../dataClass/v1/auth/res/createUser.go <<<< i want use this in swag doc
2. ../dataClass/v2/auth/res/createUser.go
3. ../dataClass/v1/file/res/createUser.go
有一个api如下。在此 api 示例中,我想在 @success 200 {object} res.UserCreateRes 行中使用上面指示的 dataClass 编号 1,但路径是重复的。
// @Summary 게스트 유저를 생성합니다
// @Description 게스트 유저를 생성합니다.
// @Tags 회원
// @Accept json
// @Produce json
// @Success 200 {object} res.UserCreateRes <<<<<<<<<<<<<<<<<<<<<
// @Failure 400 {object} common.DetaultError
// @Router /v1/auth/guestRegister [post]
我想准确地表示我想要的数据类,但我不知道该怎么做。接下来我可以尝试什么?
swag
查找包而不是文件路径。在这种情况下,所有数据类都位于名为 res
的包中,并且它们都共享相同的名称 createUser
。
swag
无法解析重复的资源,可能会返回 cannot find type definition: res.UserCreateRes
。
解决方法是为每个数据类自定义显示名称
../dataClass/v1/auth/res/createUser.go
type UserCreateRes struct {} //@name v1.res.createUserRes
../dataClass/v2/auth/res/createUser.go
type UserCreateRes struct {}//@name v2.res.createUserRes
API注释中:
// @Success 200 {object} v1.res.createUserRes