具有查询字符串的 Swagger API

编程入门 行业动态 更新时间:2024-10-21 07:47:54
本文介绍了具有查询字符串的 Swagger API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想部署一个带有查询字符串的 API.这就是 API

I want to deploy an API which is having query string.This is the API

v1/products?q=circuit breaker&locale=en-GB&pageSize=8&pageNo=1&project=GLOBAL

这是我的实施方式

"/v1/products?q={searchText}&locale={ctrCode}&pageSize={pageSize}&pageNo={pageNo}&project={project}&country={country}":{ "get":{ "tags":[ "Search Text" ], "summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", "description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", "operationId":"getProductName", "produces":[ "application/json", "application/xml" ], "parameters":[ { "name":"searchText", "in":"path", "description":"The Product that needs to be fetched", "required":true, "type":"string" }, { "name":"ctrCode", "in":"path", "description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.", "required":true, "type":"string" }, { "name":"pageSize", "in":"path", "description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.", "required":true, "type":"number" }, { "name":"pageNo", "in":"path", "description":"The Product pageNo that needs to be fetched. Example=1,2 etc.", "required":true, "type":"number" }, { "name":"project", "in":"path", "description":"The Project that needs to be fetched. Example=Mypact, DSL etc.", "required":true, "type":"string" }, { "name":"country", "in":"header", "description":"The Country that needs to be fetched. Example=France, India etc.", "required":false, "type":"string" } ], "responses":{ "200":{ "description":"successful operation", "schema":{ "$ref":"#/definitions/Products" } }, "400":{ "description":"Invalid Product_id supplied" }, "404":{ "description":"Product not found" } } } }

国家在此为可选参数.我希望 URL 仅在用户输入某个值时才显示国家/地区,否则不应在 URL 中显示.

The country is optional parameter in this. I want the URL should display country only when if user enter some value, else it should not be displayed in the URL.

推荐答案

您不能在 Swagger 中将查询参数描述为路径的一部分.您必须将这些显式声明为查询参数.

You can't describe query parameters as part of the path in Swagger. You have to declare those explicitly as query parameters.

"/v1/products":{ "get":{ "tags":[ "Search Text" ], "summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", "description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)", "operationId":"getProductName", "produces":[ "application/json", "application/xml" ], "parameters":[ { "name":"searchText", "in":"query", "description":"The Product that needs to be fetched", "required":true, "type":"string" }, { "name":"ctrCode", "in":"query", "description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.", "required":true, "type":"string" }, { "name":"pageSize", "in":"query", "description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.", "required":true, "type":"number" }, { "name":"pageNo", "in":"query", "description":"The Product pageNo that needs to be fetched. Example=1,2 etc.", "required":true, "type":"number" }, { "name":"project", "in":"query", "description":"The Project that needs to be fetched. Example=Mypact, DSL etc.", "required":true, "type":"string" }, { "name":"country", "in":"query", "description":"The Country that needs to be fetched. Example=France, India etc.", "required":false, "type":"string" } ], "responses":{ "200":{ "description":"successful operation", "schema":{ "$ref":"#/definitions/Products" } }, "400":{ "description":"Invalid Product_id supplied" }, "404":{ "description":"Product not found" } } } }

更多推荐

具有查询字符串的 Swagger API

本文发布于:2023-11-17 12:08:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   Swagger   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!