Skip to content

BaseJsonApiController Endpoint Issue #1697

@FrozenSilence

Description

@FrozenSilence

SUMMARY

When extending the BaseJsonApiController endpoints are being created for methods that have not been overridden in the child controller and/or do not have annotations.

DETAILS

public class LocationsController(
    IJsonApiOptions options,
    IResourceGraph resourceGraph,
    ILoggerFactory loggerFactory,
    IResourceService<Location, uint> resourceService) : BaseJsonApiController<Location, uint>(options, resourceGraph, loggerFactory, resourceService)
{
    /// <inheritdoc />
    [HttpGet]
    [HttpHead]
    [Authorize(Policy = "view")]
    public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
    {
        return await base.GetAsync(cancellationToken);
    }
}

Will generate

Route: api/locations
  Handler: Project.Controllers.LocationsController.GetAsync (Project)

Route: api/locations/{id}
  Handler: Project.Controllers.LocationsController.GetAsync (Project)

Route: api/locations/{id}
  Handler: Project.Controllers.LocationsController.GetAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.GetSecondaryAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.GetRelationshipAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.PostAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.PostRelationshipAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.PatchAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.PatchRelationshipAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.DeleteAsync (Project)

Route: api/locations
  Handler: Project.Controllers.LocationsController.DeleteRelationshipAsync (Project)

This also causes a problem because if you attempt to PATCH api/locations (without an id) you should receive a method not allowed but instead receive a 500-error stating it is ambiguous. Is this functionality intended?

Program.cs Middleware Order:

app.UseHttpsRedirection();
app.UseAuthentication();
app.UseRateLimiter();
app.UseAuthorization();
app.UseJsonApi();
app.MapControllers();
app.Run();

VERSIONS USED

  • JsonApiDotNetCore version: 5.6.0
  • ASP.NET Core version: 9.0.2
  • Entity Framework Core version: 9.0.2
  • Database provider: MySQL

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions