-
Notifications
You must be signed in to change notification settings - Fork 712
ODataQueryOptions parameter on method generates over 1600 parameters in Swagger UI #599
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
Comments
Weird. This has been reported before, but I'm not sure exactly what causes this. I can't seem to find the related issue, but I remember it. The most bizarre thing is that the samples, such as this one, demonstrate using ODataQueryOptions and that doesn't happen. Do you happen to have the world's simplest repro? There's clearly something different about what some people are doing versus the examples that trigger this behavior. Even more strange is that ODataQueryOptions seems to be treated as a bound model, but it shouldn't because its model binder states that it's special (CancellationToken is another example of this type of behavior). There seems to be more to the story because if that was the only issue, I still wouldn't expect it to yield 1600 parameters! That to me is baffling. Sounds like some type of recursion or something. |
Hello. First of all allow me to apologize for dropping that on you on a Friday. I'll see if I can get a small repo whipped up to demonstrate and I'll link it here. |
I just realized I completely dropped the ball on this. I'll remind myself to get something to you soon. |
No problem. I was reviewing the issues and I found the related issue. #529 refers to a similar behavior with 1700+ parameters. |
does anyone have any update on this question? In my case, if I don't have the I just need to produce actually 2 of them that are related to the same route, in this case
any idea how can I get rid of the others that are automatically added? |
@zinov that is somewhat of an unrelated issue. This looks like Swashbuckle. Honestly, this is close to what I would expect to see for OData. There are many variations of output formatters, which map to media types. There are few unrelated to OData that you could probably remove from your configuration (ex: It would seem that the Swashbuckle library now just assumes this unless you use the ProducesAttribute and ConsumesAttribute, which is wrong. This breaks things for people that version or do anything else with media type. I don't know why that decision was made, but it is also solved by re-adding things via a IOperationFilter. |
@DoctorGamester did you happen to have a repro of the problem. That would be immensely useful in trying to track down the problem. |
I was able to confirm there was an edge case where things might be explored incorrectly. It seems to be related to |
@commonsensesoftware I'll leave it up to you if you want to officially reopen this issue, but I am also experiencing this problem. I've added another sample project to my repo that demonstrates the issue. https://github.com/engenb/AspNetCore.OData.Issues/tree/main/src/Issue599 start project Issue599 and point your browser at |
@engenb it doesn't seem that your sample project has updated its references with the fix. The fix is in If this problem is still happening in |
I can't reproduce with |
I'm still experiencing this error. Even on 5.0.0. This is how my controller is implemented: [HttpGet("projects/{projectId}/issues")]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<GeminiIssue>), Status200OK)]
[ProducesResponseType(Status400BadRequest)]
public async Task<IActionResult> GetGeminiIssues(long projectId, ODataQueryOptions<GeminiIssue> options)
{
var validationSettings = new ODataValidationSettings()
{
AllowedQueryOptions = Select | OrderBy | Top | Skip | Count | Filter,
AllowedArithmeticOperators = AllowedArithmeticOperators.None,
AllowedFunctions = AllowedFunctions.None,
AllowedLogicalOperators = AllowedLogicalOperators.All,
MaxTop = 20,
};
try
{
options.Validate(validationSettings);
}
catch (ODataException d)
{
return BadRequest(d.Message);
} Endpoints:
And this is what swagger shows: This is also strange and only happens when i have odata. When I send a http://localhost:45179/odata/projects/184/issues?$top=1 I get first an Exception But it continues and i get the data, I've prepared a reproduceable project and just added you. @engenb Is it working on your side? Thanks, |
@mlop3s Were you able to solve the problem? I have the same errors you have. |
Same problem here in 5.0.4 [EnableQuery]
[HttpGet]
public IQueryable<DeliveryNote> Get(ODataQueryOptions<DeliveryNote> options) {}
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireAuthorization();
endpoints.EnableDependencyInjection();
endpoints.Select().Filter().OrderBy().MaxTop(100).Count();
}); <PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.2" /> |
I made a minimal repro of the problem: ODataIssue559. |
Hi, on my case i've just removed the projects: from: to: and it worked. Cheers, |
@DoctorGamester, @engenb, @mlop3s (and anyone else I missed) In the @davidebriscese repro, he is using part of OData; e.g. just the query options. This is actually a supported scenario because it just does some LINQ query expression manipulation without the rest of OData. The problem is that without the rest of the OData services, key metadata parts are missing. The thing missing that will cause this is the OData model binders. Without that registered, Cross-referencing this information is what makes me think your routes are not correctly configured; they are being explored as non-OData routes and |
If I have a method like this:
The moment I change it to have ODataQueryOptions, like this:
public IActionResult Get(ODataQueryOptions<Person> options)
Suddenly over 1600 parameters are generated by the Swagger UI, and a RequestBody that is normally null becomes full of information as well. It also takes an extremely long time to show these parameters when I click on the method in the UI.
I currently get around this by using the following code for a DocumentFilter:
I am using the following packages, and targeting .NET Core 3.1:
Am I doing something wrong? Have I run into a support issue, or more an issue where I am not quite using the library combination properly?
The text was updated successfully, but these errors were encountered: