Closed bastienlemaitre closed 4 years ago
Those methods don't look like valid Api/ OData Methods... I think you have two alternatives:
Set ODataRoute as an attribute in the method:
[System.Web.OData.Routing.ODataRoute("Customers({ID})/GetCards()")]
Or declare GetCards and GetCity as Functions.
Something like:
modelConfiguration.AddEntity<Customer>("ESocialEvents") .Function("GetCards") .ReturnsFromEntity<Card>("card");
You can get more information here:
https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions
Hi.
I'm experiencing the same issue.
I expected Swashbuckle.OData to automatically discover that route without having to decorate the method with the ODataRoute
attribute.
If a similar method is in an ApiController
, it will automatically be discovered by Swashbuckle, without requiring the method to be decorated with the Route
attribute.
I'm not sure if those are classified as being actions or functions.
They're navigation properties based on entity relationships, and may also be known as sub-resources. See https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/entity-relations-in-odata-v4.
Those methods are automatically generated when adding a new controller using the "Web API 2 OData v3 Controller with actions, using Entity Framework" file template for example.
Thank you.
This issue seems to be the same: https://github.com/domaindrivendev/Swashbuckle/issues/693
I'm not sure about how it should work, but in my case it works well with methods in controllers with the same name as the verb (Get, Post, Put, Patch,... ) and decorated with the attributes [HttpGet], [HttpPost]... For methods with different names I had to declare it as functions or actions (as seen in the link).
Example:
[HttpGet] public IHttpActionResult Get()
The entity should be also declared using the name of the controller.
builder.EntitySet<Model>("Model")
and the controller should inherit from ODataController:
public class ModelController : ODataController
I suggest you to take a look how the sample project of the project is made. It may help you.
I cloned the repository, built the solution, and opened the Swashbuckle.OData.Sample
project in a browser.
I navigated to /swagger
, and the swagger UI loaded without issue.
However, the /odata/Orders({orderId})/Customer
resource was not in the list as expected.
In fact, trying to do a GET request on /odata/Orders(ce37ae8d-4efe-2d5f-10a0-39ddd2436a52)/Customer
returns an unexpected error:
{
"error": {
"code": "",
"message": "No HTTP resource was found that matches the request URI 'http://localhost:4074/odata/Orders(ce37ae8d-4efe-2d5f-10a0-39ddd2436a52)/Customer'.",
"innererror": {
"message": "No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'.",
"type": "",
"stacktrace": ""
}
}
}
Yeah, I noticed there are some problem with sub-resources in the Sample project. It looks like OData just accept subresources within the navigation properties (using the parameters $expand,$filter...).
To fix that, we had to add the attributes [OdataRoute] and [ODataRoutePreffix] (optional) to the methods.
But I though we were talking about standard resources, not subresources.
I noticed that you have to have a parameter called 'key', else the method will not render.
Example:
public SingleResult Get([FromODataUri] int key) {
renders
public SingleResult Get([FromODataUri] int other) {
does not
Hi. When i'm on Swagger i can't see all methods of my odata controller. Why? Thanks