Is there a way to change the content type on the swagger UI to show odata?

Viewed 31

I'm working on a .NET 6 Web API using swagger. On the Swagger UI we have the queryable functionality working, but on our operations the content type in the response header still says the content-type is "application/json" and doesn't have the odata information which is an issue on the client side. I can see the media types in the example enter image description here

In the actual response header though this is what I'm seeing. enter image description here Is there a way to enable this either in the controller or in the startup? This is the operation in the controller

[HttpGet]
    [Route("summary/odata")]
    [EnableQuery()]
    [ProducesResponseType(200, Type = typeof(List<SubmissionSummaryDTO>))]
    [ProducesResponseType(400, Type = typeof(ApiProblemDetailsValidationErrorResponse))]
    [ProducesResponseType(404, Type = typeof(ProblemDetails))]
    [ProducesResponseType(422, Type = typeof(ProblemDetails))]

    public async Task<ActionResult<List<SubmissionSummaryDTO>>> GetSummaryOdata()
    {
        try
        {
            var results = await _manager.GetSubmissionSummaries();
            if (results == null)
            {
                ProblemDetails problemDetails = new ProblemDetails { Detail = $"No Submissions found.", Status = 404, Title = "Not Found." };
                _logger.Information($"Submissions were not found.");

                return NotFound(problemDetails);
            }
            return Ok(results);
        }
        catch (SampleMgrException ex)
        {
            _logger.Error(ex.Message);

            throw new ApiException(ex, 400);
        }
        catch (Exception ex)
        {
            _logger.Error(ex.Message);

            throw;
        }
    }

This is the Startup.cs for using Odata

services.AddControllers()
            
            .AddOData(option => 
            { 
                option.EnableQueryFeatures(100);
            })
            

Then there's an operation filter to allow swagger client generation

c.OperationFilter<Controllers.EnableQueryFilter>();

Does Swagger have any options like ProduceResponse where we can define a schema, but in this case a content-type?

0 Answers
Related