-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Bug]: Operation parameter with [FromForm] should not be used to describe a request body if more than one such parameter #3038
Comments
When will there be an update? @martincostello |
Whenever someone picks it up. Contributions welcome. |
I am thinking in picking it up. With this code you will see what I am referring to: public sealed class BodyFilter : IRequestBodyFilter
{
public void Apply(OpenApiRequestBody requestBody, RequestBodyFilterContext context)
{
if (context.FormParameterDescriptions?.Any() ?? false)
{
foreach (var (_, mediaType) in requestBody.Content)
{
if (mediaType?.Schema?.Properties?.Any() ?? false)
{
foreach (var (nameForProperty, schemaForProperty) in mediaType.Schema.Properties)
{
schemaForProperty.Description = $"{nameForProperty} Description";
}
}
}
}
}
} |
To be honest I'm not sure - the lines are getting blurred a bit between the C# parameters and the OpenAPI parameters, which is what probably what confused me in the first place with the incorrect behaviour. |
I am still studying this issue @qcjxberin for now I have a WorkAround that is to put those 3 properties inside a class with the documentation of the Properties. At first I thought that the XmlSchemaFilter was missing looking for ParameterInfo (Because this class is the one that is documenting the properties inside a class, but I am having problems with the IntegrationTests. The problem I have is that I end up duplicating so much in the OpenApi document :( however all the info inserted is right: |
I do not have clear what to do. Because for me it's a Parameter as if it was a QueryParameter. For sure that the description of the body of a FromForm couldn't be set from part of the parameters when there are more than one but I am not sure what to do |
(I haven't forgotten about this, it's in my todo pile, but I need to sit and think about it properly to give an answer about how to proceed) |
For the purposes of this issue, I think the intention is exactly as described originally - refactor the code to not use That doesn't actually make things behave as the OP wants with respect to documentation for form parameters, but it corrects the duplication of the descriptions from the original attempt to fix it. |
Describe the bug
As part of #3020 to fix #3018, a change was made to fix XML comments not being used to describe the request body for a form.
On reflection, this fix wasn't correct as if there are multiple parameter the first parameter is used to describe the request body in its entirety: #3018 (comment)
Expected behavior
The request body should only be documented from the XML documentation for a
[FromForm]
-annotated argument if there is exactly one such parameter.Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs
Lines 17 to 26 in 7a7230d
Actual behavior
The request body is documented from the XML documentation from the first of multiple arguments with
[FromForm]
.Steps to reproduce
Render the OpenAPI document for an application including the following controller:
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.7.1
.NET Version
8.0.8
Anything else?
No response
The text was updated successfully, but these errors were encountered: