This is a bit of a more complex scenario than binding a comma delimited query parameter string to an array of those comma tokenized values.
Basically I have a simple entity model called User:
public class User
{
public string Name { get; set }
public int Age { get; set; }
// rest ommited
}
I'd like to be able to provide multiple names and ages in my web api endpoint like such:
http://localhost/api/data/user/query?name=chris,john,alex&age=28,35
which would bind to an ARRAY of user filters (i'm just using the entity model). And also Swagger would show the test input form as if it was a single User fields you are entering in.
How can this be done with AspDotNetCore 2.0 Web Api and Swashbucke without having to create a new model with strings and tokenize on comma. I'd love to create some kind of Swashbuckle/AspNetCore hook (decorate method parameter with some attribute) that would then know to split inputs into seperate models.
The idea being I generate the filter Expression> for filtering data from a repository using the collection of filter values:
var exampleExpression = entity => (entity.Name.Contains("chris") || entity.Name.Contains("john") || entity.Name.Contains("alex")) && (entity.Age == 28 || entity.Age == 35);
Generating the Expression tree programatically I can do.
I'm even playing with the idea of taking the inputs and putting them into a dictionary for lookup when generating the filter expression. But I'd love to hear your thoughts and solution.