Skip to content

Form Collection Handling ​

According to OpenAPI specification, collections in URI query or form fields support 5 representation formats:

FormatDescription
CsvComma-separated
SsvSpace-separated
TsvBackslash-separated
PipesPipe-separated
MultiMultiple key-value pairs with the same name

Example ​

For an array value like id = ["001", "002"], when processed by PathQueryAttribute or FormContentAttribute:

CollectionFormatData
[PathQuery(CollectionFormat = CollectionFormat.Csv)]id=001,002
[PathQuery(CollectionFormat = CollectionFormat.Ssv)]id=001 002
[PathQuery(CollectionFormat = CollectionFormat.Tsv)]id=001\002
[PathQuery(CollectionFormat = CollectionFormat.Pipes)]id=001|002
[PathQuery(CollectionFormat = CollectionFormat.Multi)]id=001&id=002

Usage Example ​

csharp
public interface IUserApi
{
    [HttpGet("api/users")]
    Task<List<User>> GetAsync(
        [PathQuery(CollectionFormat = CollectionFormat.Multi)] int[] ids);
}

Resulting request: api/users?ids=1&ids=2&ids=3