Skip to content

JsonApiDotNetCore.BaseJsonApiController<TResource, TIdentifier> not able to limit routes #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bhavik-mittal opened this issue Sep 18, 2023 · 5 comments
Labels

Comments

@bhavik-mittal
Copy link

I have created a custom controller Which inherits from BaseJsonApiController<> and i have overridden methods like GetAsync, GetById, PatchResource, PostResource. So while running the application getting error from swagger that says : An unhandled exception has occurred while executing the request. Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Ambiguous HTTP method for action - Controllers.RaceController.GetSecondaryAsync. Actions require an explicit HttpMethod binding for Swagger/OpenAPI 3.0

Also, even if i use specific service then also it generates all the controller endpoints Example :

public class BaseController<TResource, TIdentifier> : BaseJsonApiController<TResource, TIdentifier> where TResource : class, IIdentifiable where TIdentifier : struct { public BaseController(IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IGetAllService<TResource, TIdentifier> getAllService) : base(options, resourceGraph, loggerFactory, getAllService) {

} }

Now in the above example it will create endpoints for PostAsync as well which it should not as per the documentation.

I wanted to get only the routes endpoint generated for those the methods has been overridden from the BaseJsonApiController but currently it is generating all the endpoints. I am using version 5.3.0 of JsonApiDotNetCore

@bkoelman
Copy link
Member

See #1285 (comment).

@bhavik-mittal
Copy link
Author

Currently as a workaround for the managing the request and response structure according to json:api I have used the Swashbuckle.AspNetCore.SwaggerGen.IOperationFilter and IDocumentFilter.

But If i have injected only IGetAllService<TResource, TIdentifier> in the BaseJsonApiController<TResource, TIdentifier> constructor then also i am able to hit the Post Url. Is there any way to restrict that?

So, Is there any way to only expose the partial resource endpoints using the BaseJsonApiController<TResource, TIdentifier> ?

@bkoelman
Copy link
Member

I honestly have no idea. Did you try the openapi branch?

@bkoelman
Copy link
Member

This looks like a duplicate of #1052.

@bkoelman bkoelman closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@bkoelman
Copy link
Member

@bhavik-mittal I have a fix for this ready in #1450. See also #1052 (comment) for context.

Before starting to work on this PR, I wasn't able to give you a good answer because I didn't know how this was implemented. The original code was written by @maurei, who isn't active on the project anymore. I'm picking up from there, still learning. I think I understand your issue now. Can you let me know if the PR solves the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants