-
Notifications
You must be signed in to change notification settings - Fork 135
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
UnboundOperation throws an exception #764
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;
} |
You need to add string parameters to the operations. |
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>();
// ...
}
});
} |
Hello, This is how I'm calling it:
And when I do, I get this exception:
Thanks! |
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": "[email protected]"
}
} You may need to adjust the formatting accordingly for Postman or other tools |
Thanks, thats for an Action, for a function with GET? |
A simple GET request is unlikely to work because it requires |
Oh, ok, thanks! I'll try that and come back with results. |
No matter how I try to call this function with the String Parameter is not working, even with the ODataClient. |
Important {
"input": { <== update this
"@odata.type": "#MyCompany.MyModels.Dto.Request.StringRequest", // <== correct this checking it from the `/odata/$metadata`
"Value": "[email protected]"
}
}
|
If you create an
[UnboundOperation]
(by the wayOperation
is 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
BoundOperation
the error goes away but they are completely ignored in Swagger.Any thoughts?
Thank you!
The text was updated successfully, but these errors were encountered: