gpt4 book ai didi

使用路径参数 Swagger

转载 作者:IT王子 更新时间:2023-10-29 02:32:13 25 4
gpt4 key购买 nike

路线:

// swagger:route DELETE /v1/path/{id} api DeleteV1
//
// Deletes an item.
//
// Schemes: https
//
// Responses:
// 202: AcceptedResponse
// 401: UnauthorizedErrorResponse
// 500: InternalServerErrorResponse
"/v1/path/{id}": {
"DELETE": Handle(DeleteRequest{}),
"OPTIONS": s.handleOptionsRequest,
},

参数/响应模型:

// Description
//
// swagger:parameters DeleteV1
type DeleteRequest struct {
// id of an item
//
// In: path
id string `json:"id"`

cookies []*http.Cookie
}

// Description
//
// swagger:response DeleteResponse
type DeleteResponse struct {
}

无论我怎样尝试,我总是得到 - path param "{id}"has no parameter definition

端点仅采用路径参数“id”、cookie(它们在 swagger 模型中不可见)并返回空主体和 HTTP 状态代码。

如何让 go-swagger 看到“{id}”的“参数定义”?

最佳答案

需要导出struct字段。尝试:

type DeleteRequest struct {
// ID of an item
//
// In: path
ID string `json:"id"`

关于使用路径参数 Swagger ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46696584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com