下面是我的代碼:// swagger:route GET /user_list get_user//// Get a user profile// Parameters:// user_id: userParam// Consumes:// - application/json// Produces:// - application/json//// Responses:// 200: UserResponse在我的請求模型中,我添加了如下參數(shù):// swagger:parameters userParamtype UserRequest struct { // aaaa // in: query UserId string `json:"user_id"`}生成不可靠的json時出現(xiàn)錯誤。panic: assignment to entry in nil mapgoroutine 1 [running]:github.com/go-swagger/go-swagger/scan.(*setOpParams).Parse(0xc428986a20, 0xc426439f30, 0x1, 0x1, 0x0, 0x0) /home/sotsys-056/go_10/src/github.com/go-swagger/go-swagger/scan/route_params.go:137 +0x635github.com/go-swagger/go-swagger/scan.(*tagParser).Parse(0xc426e873d0, 0xc426439f30, 0x1, 0x1, 0x0, 0xc426439f30) /home/sotsys-056/go_10/src/github.com/go-swagger/go-swagger/scan/scanner.go:526 +0x52當我刪除參數(shù)部分時,它工作正常,我不會生成swagger json,但是帶有參數(shù)我無法生成它。我也嘗試過這些方法。// Parameters:// - user_id: [in:query required:true type:string] Description goes herparameters: - name: user_id in: query description: this argument is a string schema: type: string
1 回答

慕碼人2483693
TA貢獻1860條經(jīng)驗 獲得超9個贊
您的示例不完整。但是,使用您已有的代碼,您的代碼應(yīng)該看起來像最簡單的形式:
// swagger:parameters GetUser
type GetUser struct {
// UserId that identifies a user.
//
// in: query
UserId string `json:"user_id"`
}
// Returns a user.
// swagger:response UserResponse
type UserResponse struct {
// in: body
Body struct {}
}
// swagger:route GET /user_list GetUser
//
// Get a user profile.
//
// Responses:
// 200: UserResponse
router.Get("/user_list", handler.GetUser)
注意我們有三件事:
請求對象
響應(yīng)對象
同時使用請求和響應(yīng)對象的路由
- 1 回答
- 0 關(guān)注
- 338 瀏覽
添加回答
舉報
0/150
提交
取消