Swagger query parameter template

痴心易碎 提交于 2019-12-11 15:52:40

问题


I have on query parameter which is little bit complex and i have my own syntax to make that value. Its has more then one variable to make one complete string value. Let suppose name of parameter is index which has row and column like to make this value 20:30

index =  { row: 20, col:30 }
index2 = { row: 20, col:30, chr: 15 }

Now i wanted to make it as

example.com?index=20:30
example.com?index2=20:30:15

Can someone tell me how can i define this in swagger ? Thank you.


回答1:


Make your swagger parameter a string and in your code behind handle the splitting into multiple variables...

I do exactly that here: http://turoapi.azurewebsites.net/swagger/ui/index#/Echo/Echo_Get

"parameters": [
{
    "name": "location",
    "in": "query",
    "description": "SoFL= 26.16,-80.20",
    "required": true,
    "type": "string"
},

That location is (Latitude,Longitude) and I split it with a C# TypeConverter
...and the request looks like:
http://turoapi.azurewebsites.net/api/Echo?location=26.16,-80.20



The code for that WebApi is here: https://github.com/heldersepu/TuroApi



来源:https://stackoverflow.com/questions/45485397/swagger-query-parameter-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!