Open MuQuanyu opened 2 months ago
It may be the case that you're seeing the intermediate state when the document is in the process of being built-up and that the information isn't available yet.
What do you see if you inspect the operations as part of a document filter?
FYI there's information here about when each type of filter runs: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2993#issuecomment-2245802023
Seeing the filter that you have created it's very similar to what the SwagerIgnoreAttribute makes under the hood, so you could take a look there.
If it's not the same I need a repro to look at it
Describe the bug
In the
Apply
method of theIOperationFilter
interface, all schemas inoperation.RequestBody.Content
are eithernull
or have aCount
of0
.I've tested a lot of things like public string testiges noreparams ([FromBody] Person person) { return $"{person.Id},{person.Name},{person.Gender},{person.Age}"; Such an interface has also changed the entity class type of many request bodies, but it is still in the filter and cannot get those parameters.Expected behavior
Since I want to filter out some of the attributes in the request body that are generated on swagger, to implement this also annotate, then I have to take advantage of your filter! This is to implement the Apply method in the IOperationFilter interface. But I can't get the Schema of the request body, which makes me unable to implement this feature, I can only use reflection mechanism to enforce the implementation.
Actual behavior
What actually happens is that you don't get it. And I also enforced the use of reflection to fulfill my needs. The code snippet is attached.
Steps to reproduce
No response
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.7.0
.NET Version
net6.0
Anything else?
using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; using System.Reflection; using Microsoft.AspNetCore.Mvc;
namespace WebApplication2.Attributes.Filter { public class IgnoreParamsOperationFilter : IOperationFilter { public void Apply(OpenApiOperation operation, OperationFilterContext context) { var ignoreParamsAttribute = context.MethodInfo .GetCustomAttributes(true) .OfType()
.FirstOrDefault();
}