0

Is there any reason why it always returns a validation error?

Here's the screenshot:

enter image description here

Here's my enum schema filter code:

public class EnumSchemaFilter : ISchemaFilter
{
    public void Apply(OpenApiSchema model, SchemaFilterContext context)
    {
        if (context.Type.IsEnum)
        {
            model.Enum.Clear();
            Enum.GetNames(context.Type)
                .ToList()
                .ForEach(n => model.Enum.Add(new OpenApiString(n)));
        }
    }
}

Enum Model:

public enum QuoteStatus
{
    New = 0,
    Confirmed = 10,
    Completed = 100
}

Controller:

 [Route("/v{v:apiVersion}/Campaigns/{propertyNo}/[controller]", Name = nameof(GetCampaignQuote))]
    [HttpGet]
    public async Task<ActionResult<Quote>> GetCampaignQuote([FromRoute]int propertyNo, [FromQuery]QuoteStatus status)
    {
        var result = await _iQuoteService.GetCampaignQuote(propertyNo, status);

        if (result == null)
            return BadRequest();

        return Ok(result);
    }

Is there anyway to convert those enum string to integer data type? Or is there a way to change the data type of the parameter to be an enum type?

Carlo Luisito
  • 179
  • 1
  • 15

0 Answers0