OData API explorer only showing $select and $expand, help #1038
-
Hi, Does anyone know what might cause the API explorer to only show I've enabled all query options globally and query options like I'm still targeting .NET 6.0, maybe I'm using an invalid combination of packages? <ItemGroup>
<PackageReference Include="Asp.Versioning.OData" Version="6.4.0" />
<PackageReference Include="Asp.Versioning.OData.ApiExplorer" Version="6.4.1" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.2.3" />
<PackageReference Include="Microsoft.OData.Core" Version="7.18.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.4.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup> My middleware pipeline config: var mvc = services.AddControllers();
services.AddEndpointsApiExplorer();
mvc.AddOData((odata, sp) =>
{
// Enable all query features globally
// You can restrict features per endpoint using [EnableQuery(AllowedQueryOptions = ...)]
odata.EnableQueryFeatures(maxTopValue: 100);
});
var versioning = services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(4, 0);
// Reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
options.ReportApiVersions = true;
// Allows a client to make a request without specifying an api-version
// The value of options.DefaultApiVersion will be assumed
options.AssumeDefaultVersionWhenUnspecified = true;
});
versioning.AddOData((odata) =>
{
odata.AddRouteComponents("odata");
});
versioning.AddODataApiExplorer(options =>
{
// Add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
// Note: the specified format code will format the version as "'v'major[.minor][-status]"
options.GroupNameFormat = "'v'VVV";
}); My controller: I noticed the use of [ApiVersion(4.0)]
public class DocumentsController : ODataController
{
private ILogger<DocumentsController> _logger;
public DocumentsController(ILogger<DocumentsController> logger)
{
_logger = logger;
}
[EnableQuery]
[Produces("application/json")]
[ProducesResponseType(typeof(IQueryable<DocumentODataDTO>), Status200OK)]
[ProducesResponseType(Status400BadRequest)]
[ProducesResponseType(Status401Unauthorized)]
[ProducesResponseType(Status403Forbidden)]
public async Task<ActionResult<IQueryable<DocumentODataDTO>>> GetDocuments(
[FromHeader(Name = "X-BusinessUnitCode"), Required] string businessUnit,
[FromServices] IMediator mediator,
[FromServices] IConfigurationProvider mapperConfiguration,
CancellationToken ct)
{
} If I remove the I might just be using the attributes incorrectly? Thanks for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
OData, both in protocol and implementation, only supports returning JSON or XML. To be fully compliant, the payloads are supersets that are specific to OData. You cannot return just any 'ol JSON. I'm not sure if XML is even still supported. I know it's not by default. In the context of OData, there should be no need to specify I have also found Swashbuckle was adding |
Beta Was this translation helpful? Give feedback.
OData, both in protocol and implementation, only supports returning JSON or XML. To be fully compliant, the payloads are supersets that are specific to OData. You cannot return just any 'ol JSON. I'm not sure if XML is even still supported. I know it's not by default.
In the context of OData, there should be no need to specify
[Produces]
. OData-based responses will list the equivalent values from the ODataInputFormatter
andOutputFormatter
implementations. The API Explorer knows that the results are for OData because you are usingODataController
, which has[ODataRouting]
applied. You should notice that there are actually several media types reported (but you probably expected one). You'…