SledgeHammer
SledgeHammer

Reputation: 7736

.Net Core Swagger not working with Required enum?

Using Swashbuckle 5.6.3. Controller method looks like:

public async Task<IActionResult> GenerateTokenAsync([FromForm] TokenCredentials tokenCredentials)

TokenCredentials looks like:

    [Required]
    public GrantType? grant_type
    {
        get;
        set;
    }

GrantType looks like:

public enum GrantType
{
    client_credentials = 0
}

The enum shows in Swagger and shows as required, but when I hit the execute button, I get the red bounce of death. If I take off the Required, then it executes. I also tried NotNull, but that let it through regardless.

Am I missing something?

Upvotes: 0

Views: 622

Answers (1)

Yiyi You
Yiyi You

Reputation: 18209

You can use Swashbuckle.AspNetCore 5.5.0,it's OK. Here is an official document

Result: enter image description here

Or you can delete [FromForm] in Swashbuckle 5.6.3.

Upvotes: 1

Related Questions