Swagger query parameter template

2019-08-20 08:39发布

问题:

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