如何在Go的kin-openapi/openapi3中为Swagger参数设置Example值
为kin-openapi路径参数设置Example值
你可以通过两种方式给路径参数添加Example值:
方式1:通过Schema设置Example
直接在创建的StringSchema上调用WithExample()方法传入示例值:
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().WithExample("SUBS-12345")), }, }, }, }, }
方式2:直接给Parameter设置Example
也可以跳过Schema,直接调用Parameter的WithExample()方法绑定示例:
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()). WithExample("SUBS-12345"), }, }, }, }, }
两种方式都能生成符合OpenAPI规范的示例值,可根据实际需求选择。
内容的提问来源于stack exchange,提问作者Arun M
相关产品推荐
相关产品推荐

