I am currently developing a .net core web API that will use a swagger as its documentation. Everything was perfect, except almost of the request method has a required data that was in the header. My problem was how to add an input header in the Swagger UI. After a few research, I found it. Here's how to do it. Create a filter class that implement IOperationFilter public class MyCustomHeaderFilter : IOperationFilter { public void Apply(OpenApiOperation operation, OperationFilterContext context) { if (operation.Parameters != null) { operation.Parameters.Add(new OpenApiParameter { Name = "FilterName", In = ParameterLocation.Header, Description = "access token", Required = false, }); } } } Register the class in swagger using OperationFilter ...
In order to display the description of the parameter specified in the action. You have to enable xml generation in your project property and enable it in swagger option. services.AddSwaggerGen(swagger => { swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "ArchiveOne WebApi", Version = "v1" }); var basePath = PlatformServices.Default.Application.ApplicationBasePath; foreach (var name in Directory.GetFiles(basePath, "*.XML", SearchOption.AllDirectories)) { swagger.IncludeXmlComments(name); } });
The default json size configured in asp.net mvc is 2097152. You can change it or add in the web.config < configuration > < system.web.extensions > < scripting > < webServices > < jsonSerialization maxJsonLength = "50000000" /> </ webServices > </ scripting > </ system.web.extensions > </ configuration >
Comments
Post a Comment