dommer
dommer

Reputation: 19810

Can I configure Swagger UI to accept and empty array using Swashbuckle?

I have the following Web API action

public IEnumerable<ItemDto> Get([FromUri] int[] itemNumbers)

itemNumbers are passed as

?itemNumbers=1&itemNumbers=2

I'm documenting it using Swashbuckle (Swagger).

The API can accept an empty list (no item numbers), which is functionality I wish to have. However, the Swagger UI reports

Provide multiple values in new lines (at least one required).

Is there a way to allow the itemNumbers parameter to be empty in the Swagger UI?

Upvotes: 0

Views: 1335

Answers (1)

BRAHIM Kamel
BRAHIM Kamel

Reputation: 13765

you have to try this

[Route("api/{itemNumbers}")] 
[Route("api/")] //when itemNumbers not provided it will be null 
public IEnumerable<ItemDto> Get([FromUri] int[] itemNumbers=null)

Upvotes: 3

Related Questions