如何在GO中的openapi3 swagger文档中设置“示例”

j0pj023g  于 2023-06-22  发布在  Go
关注(0)|答案(1)|浏览(228)

我在用
github.com/getkin/kin-openapi/openapi3
有人能告诉我如何设置参数字段的示例值吗?

swagger.Paths = openapi3.Paths{
        "/postval/subsid/{subscriberid}/updatefle": &openapi3.PathItem{
            Post: &openapi3.Operation{
                OperationID: "postvalue",
                Parameters: []*openapi3.ParameterRef{
                    {
Value: openapi3.NewPathParameter("subscriberid").WithDescription("SubscriberIdentifier").WithRequired(true).
                            WithSchema(openapi3.NewStringSchema()),
}

`我尝试设置所有参数,但无法找到设置示例的方法

bis0qfac

bis0qfac1#

首先创建参数,然后在其上设置示例。然后将其添加到路径定义中。

subscriberParameter := openapi3.NewPathParameter("subscriberid").WithDescription("SubscriberIdentifier").WithRequired(true).
        WithSchema(openapi3.NewStringSchema())
    
    subscriberParameter.Example = "exampleId"
    
    swagger.Paths = openapi3.Paths{
        "/postval/subsid/{subscriberid}/updatefle": &openapi3.PathItem{
            Post: &openapi3.Operation{
                OperationID: "postvalue",
                Parameters: []*openapi3.ParameterRef{
                    {
                        Value: subscriberParameter,
                    },
                },
            },
        },
    }

相关问题