有用过 go-swagger 的大佬么 请教几个问题

2021-01-19 12:57:42 +08:00
 Goat121

1. 我在服务器上用 swagger serve 把服务启在 7500 端口,点测试的时候也访问了 7500,但是我要测试的业务启在 7501,怎么解决这个啊

2. 我按如下格式定义了一个 GET 请求的 form 参数,无法正确显示。这种该怎么定义呢?

// swagger:parameters download
type download struct {
	// in: path
	resource.DownloadIn
}

type DownloadIn struct {
	ResourceId string `form:"resourceId" binding:"required"`
}

3. 返回参数按如下定义,能正常显示但是 code 值一直是 0,我想显示为 200,有办法么?

// Success response
// swagger:response downloadWrapper
type downloadWrapper struct {
	// in: body
	Body struct {
		Code int                `json:"code"`
		Msg  resource.UploadOut `json:"msg"`
	}
}

多谢指教🙏🙏🙏

1633 次点击
所在节点    Go 编程语言
4 条回复
pwli
2021-01-19 16:32:26 +08:00
1. nginx 转发下?|| 自己渲染 swagger
2. // in: path 代表路由参数,貌似不能是复合结构
3. // example: 200
jindeq
2021-01-19 16:48:30 +08:00
没看懂
Goat121
2021-01-19 21:25:25 +08:00
@pwli 非常感谢大佬!都解决啦
Goat121
2021-01-22 20:21:40 +08:00
@pwli 大佬,再请教一下,我定义了
```
// securityDefinitions:
// Bearer:
// type: apiKey
// name: Authorization
// in: header
//
```
然后在需要鉴权的接口定义了
```
// security:
// - Bearer: []
```
但是现在不知道怎样在 swagger-ui 调用 login 登陆后,把 token 给其他接口使用,类似 postman 的效果
请问这个要怎么弄

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/746270

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX