V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Goat121

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

  •  
  •   Goat121 · Jan 19, 2021 · 2513 views
    This topic created in 1925 days ago, the information mentioned may be changed or developed.

    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"`
    	}
    }
    

    多谢指教🙏🙏🙏

    4 replies    2021-01-22 20:21:40 +08:00
    pwli
        1
    pwli  
       Jan 19, 2021   ❤️ 1
    1. nginx 转发下?|| 自己渲染 swagger
    2. // in: path 代表路由参数,貌似不能是复合结构
    3. // example: 200
    jindeq
        2
    jindeq  
       Jan 19, 2021
    没看懂
    Goat121
        3
    Goat121  
    OP
       Jan 19, 2021
    @pwli 非常感谢大佬!都解决啦
    Goat121
        4
    Goat121  
    OP
       Jan 22, 2021
    @pwli 大佬,再请教一下,我定义了
    ```
    // securityDefinitions:
    // Bearer:
    // type: apiKey
    // name: Authorization
    // in: header
    //
    ```
    然后在需要鉴权的接口定义了
    ```
    // security:
    // - Bearer: []
    ```
    但是现在不知道怎样在 swagger-ui 调用 login 登陆后,把 token 给其他接口使用,类似 postman 的效果
    请问这个要怎么弄
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3569 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 10:51 · PVG 18:51 · LAX 03:51 · JFK 06:51
    ♥ Do have faith in what you're doing.