UnboundOperation throws an exception #768
Replies: 10 comments
-
|
Important Please provide a minimal repository that reproduces the issue. I am using .NET Core 8 with Restier 1.1.1, and Swagger is working correctly. Some signatures I have... [Microsoft.Restier.AspNetCore.Model.UnboundOperation]
public IQueryable<EmailAddress> GetEmailsToValidate()
{
// ...
return query.AsQueryable();
}
[Microsoft.Restier.AspNetCore.Model.UnboundOperation]
public async Task<bool> ValidateBulkAsync()
{
// ...
return isFinalRecord;
} |
Beta Was this translation helpful? Give feedback.
-
|
You need to add string parameters to the operations. |
Beta Was this translation helpful? Give feedback.
-
|
You can not. You have to define it as [Microsoft.Restier.AspNetCore.Model.UnboundOperation(OperationType = Microsoft.Restier.AspNetCore.Model.OperationType.Action)]
public IQueryable<EmailAddress> GetEmailsToValidate(StringRequest input)
{
// ...
return query.AsQueryable();
}
public class CustomModelExtender : IModelBuilder
{
public IModelBuilder InnerHandler { get; set; }
public IEdmModel GetModel(ModelContext context)
{
IEdmModel model = InnerHandler.GetModel(context);
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.ComplexType<StringResponse>();
return modelBuilder.GetEdmModel();
}
}
public class StringRequest
{
public string Value { get; set; }
}
public static IHostApplicationBuilder AddRestierInternal(this IHostApplicationBuilder builder)
{
builder.Services.AddRestier(b =>
{
// This delegate is executed after OData is added to the container.
b.AddRestierApi<ApiController>(routeServices =>
{
// ...
routeServices.AddChainedService<IModelBuilder, CustomModelExtender>();
// ...
}
});
} |
Beta Was this translation helpful? Give feedback.
-
|
Hello, This is how I'm calling it: And when I do, I get this exception: Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
To test the endpoint, use a POST request. For VSCode RestClient or Visual Studio Rest Client: ###
# @name GetEmailsToValidate
POST {{baseUrl}}/odata/GetEmailsToValidate HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache
{
"input": {
"@odata.type": "#MyCompany.MyModels.Dto.Request.StringRequest", // <== correct this checking it from the `/odata/$metadata`
"Value": "me@test.local"
}
}You may need to adjust the formatting accordingly for Postman or other tools |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, thats for an Action, for a function with GET? |
Beta Was this translation helpful? Give feedback.
-
|
A simple GET request is unlikely to work because it requires |
Beta Was this translation helpful? Give feedback.
-
|
Oh, ok, thanks! I'll try that and come back with results. |
Beta Was this translation helpful? Give feedback.
-
|
No matter how I try to call this function with the String Parameter is not working, even with the ODataClient. |
Beta Was this translation helpful? Give feedback.
-
Important {
"input": { <== update this
"@odata.type": "#MyCompany.MyModels.Dto.Request.StringRequest", // <== correct this checking it from the `/odata/$metadata`
"Value": "me@test.local"
}
}
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If you create an
[UnboundOperation](by the wayOperationis not working as it's shown in the documentation.) and you have one or 2 strings as parameters you will get this exception:This only happens for the Swagger generation. The actual queries works fine.
Assemblies affected
Microsoft.Restier.AspNetCore Version="1.1.1"
Microsoft.Restier.AspNetCore.Swagger Version="1.1.1"
Microsoft.Restier.Core Version="1.1.1"
Microsoft.Restier.EntityFrameworkCore Version="1.1.1"
Swashbuckle.AspNetCore Version="6.6.2"
Swashbuckle.AspNetCore.SwaggerGen Version="6.6.2"
Swashbuckle.AspNetCore.SwaggerUI Version="6.6.2"
Reproduce steps
As said in this comment: Issue #720
Expected result
Correctly generate the OpenApi json and Swagger UI.
Actual result
An exception is thrown when accessing the Swagger endpoint.
Additional details
If I make them
BoundOperationthe error goes away but they are completely ignored in Swagger.Any thoughts?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions