简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM