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

@Success 200 {array} json "{"code":200,"data":model.Account,"msg":"success"}" #390

Closed
dotecxy opened this issue May 6, 2019 · 8 comments

Comments

@dotecxy
Copy link

dotecxy commented May 6, 2019

example (Java generics)
type JsonResult struct{
code int
msg string
data interface{}
}

type Account struct{

}

xxxx
xxx
@success 200 {array} json "{"code":200,"data":model.Account,"msg":"success"}"
func Get() {
a:=Account{}
json:=JsonResult{code:1,msg:"",data=&a}
x.JSON(json)
}

swag init

@pei0804
Copy link
Member

pei0804 commented May 7, 2019

@ddaggHT
Copy link

ddaggHT commented May 29, 2019

Think what they are trying to ask for is a way to define a struct for a response directly in the comment rather than having to build out a struct and link it. It would be a nice feature in my opinion as some times I have single variable responses from my api's and having to make a struct with one variable inside of it in order to link it for the docs can get kind of tedious at times.

@ubogdan
Copy link
Contributor

ubogdan commented Jul 19, 2019

@ddaggHT if you are going to work with json , just declare a standard Response format like the following and you can use it as response in all controllers.

type Response struct {
    Data interface{}
}

or

type Response struct {
    Data string
}

@ubogdan
Copy link
Contributor

ubogdan commented Aug 8, 2019

Actualy is not a simple response , since "data" is a type of model.Account .
@success 200 {array} json "{"code":200,"data":model.Account,"msg":"success"}"

@ilovesusu
Copy link

type Response struct {
Code int json:"code"
Msg string json:"msg"
Data interface{} json:"data"
}
type User struct {
UserId int form:"user_id" json:"user_id" example:"1" primaryKey:"true"
UserName string form:"user_name" json:"user_name" gorm:"type:varchar(16);comment:'用户名'"
}

// @success 200 {object} utils.Response{data:model.User} "{"code":0,"data":model.User,"msg":"ok"}"

this's good ,but it don't worker

@lzz001
Copy link

lzz001 commented Mar 7, 2020

Has the above problem been solved?

@lzz001
Copy link

lzz001 commented Mar 7, 2020

Think what they are trying to ask for is a way to define a struct for a response directly in the comment rather than having to build out a struct and link it. It would be a nice feature in my opinion as some times I have single variable responses from my api's and having to make a struct with one variable inside of it in order to link it for the docs can get kind of tedious at times.

I have the same problem

@sdghchj
Copy link
Member

sdghchj commented Mar 23, 2020

Reference #651 .
@dotecxy @lzz001

@sdghchj sdghchj closed this as completed Mar 23, 2020
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

7 participants