Skip to content

how to send array parameter to my interface? #4056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
javitospfv opened this issue Dec 27, 2017 · 3 comments
Closed

how to send array parameter to my interface? #4056

javitospfv opened this issue Dec 27, 2017 · 3 comments

Comments

@javitospfv
Copy link

javitospfv commented Dec 27, 2017

when I wanted to send array parameter,I could‘t know how to write a correct string in the textbox.
please help!

I installed swagger-ui by Swashbuckle.AspNetCore;
image

Api definition:

[HttpPost]
        [Route("Polygon")]
        public async Task<IActionResult> PolygonVolumeInside(PolygonVolumeInsideParameter parameter)
        {
            var apiKey = _iconfiguration.GetSection("DroneDeploy").GetSection("Key").Value;
            var urlApi = _iconfiguration.GetSection("DroneDeploy").GetSection("UrlApi").Value;
            var client = new HttpClient();
            var culture = CultureInfo.CreateSpecificCulture("en-US");
            var points = string.Empty;
            foreach (var point in parameter.Points)
            {
                points += $"{point.Lat.ToString(culture)}%{point.Lon.ToString(culture)},";
            }
            points = points.Substring(0, points.Length - 1);
            var url = $"{urlApi}tiles/{parameter.PlanId}/elevation_profile/LINESTRING({points})?api_key={apiKey}";
            var response = await client.GetAsync(url);
            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync();
            return Ok(JsonConvert.DeserializeObject(content));
        }

Parameter classes

public class PolygonVolumeInsideParameter
    {
        public List<Location> Points { get; set; }
        public string PlanId { get; set; }
    }
public class Location
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int LocationId { get; set; }
        public decimal Lat { get; set; }
        public decimal Lon { get; set; }
    }
@javitospfv
Copy link
Author

I have tried with these values:

{"Lat":1.222,"Lon":1.222}
{"Lat":1.4344,"Lon":3.242}

@heldersepu
Copy link
Contributor

heldersepu commented Dec 31, 2017

I'm not quite sure why your UI shows 2 query parameters for the POST when your definition shows only one param, it should be on the body

Here is my take on your definition:
http://swashbuckletest.azurewebsites.net/swagger/ui/index?filter=Polygon#/PolygonVolume/PolygonVolume_Post
and I would post something like:

{
  "Points": [
    {"Lat": 1,"Lon": 2},
    {"Lat": 5,"Lon": 6}
  ],
  "PlanId": "abc"
}

If I wanted something like that on the URL the query will look like:
http://swashbuckletest.azurewebsites.net/api/PolygonVolume?p.points[0][Lat]=1&p.points[0][Lon]=2&p.points[1][Lat]=5&p.points[1][Lon]=6&p.PlanId=abc

...But this not a swagger-ui issue

better ask things like this on StackOverflow, there is a much wider audience there.

@shockey
Copy link
Contributor

shockey commented Jan 11, 2018

Closing due to inactivity.

This is simply to keep our issue tracker clean - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue.

@shockey shockey closed this as completed Jan 11, 2018
@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants