File tree Expand file tree Collapse file tree
src/Swashbuckle.AspNetCore.SwaggerGen
test/Swashbuckle.AspNetCore.SwaggerGen.Test Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,6 @@ namespace Swashbuckle.AspNetCore.Annotations
1111 /// Can be used in combination with <see cref="System.Text.Json.Serialization.JsonExtensionDataAttribute"/>
1212 /// to capture and invalidate unsupported properties.
1313 /// </remarks>
14- [ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Property ) ]
14+ [ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Parameter | AttributeTargets . Property ) ]
1515 public class SwaggerIgnoreAttribute : Attribute { }
1616}
Original file line number Diff line number Diff line change @@ -314,6 +314,7 @@ private IList<OpenApiParameter> GenerateParameters(ApiDescription apiDescription
314314 {
315315 return ( ! apiParam . IsFromBody ( ) && ! apiParam . IsFromForm ( ) )
316316 && ( ! apiParam . CustomAttributes ( ) . OfType < BindNeverAttribute > ( ) . Any ( ) )
317+ && ( ! apiParam . CustomAttributes ( ) . OfType < SwaggerIgnoreAttribute > ( ) . Any ( ) )
317318 && ( apiParam . ModelMetadata == null || apiParam . ModelMetadata . IsBindingAllowed ) ;
318319 } ) ;
319320
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ public void ActionWithIntParameterWithDefaultValueAttribute([DefaultValue(3)]int
5050 public void ActionWithIntParameterWithRequiredAttribute ( [ Required ] int param )
5151 { }
5252
53+ public void ActionWithIntParameterWithSwaggerIgnoreAttribute ( [ SwaggerIgnore ] int param )
54+ { }
55+
5356 public void ActionWithObjectParameter ( XmlAnnotatedType param )
5457 { }
5558
Original file line number Diff line number Diff line change @@ -473,6 +473,35 @@ public void GetSwagger_IgnoresParameters_IfActionParameterHasBindNeverAttribute(
473473 Assert . Empty ( operation . Parameters ) ;
474474 }
475475
476+ [ Fact ]
477+ public void GetSwagger_IgnoresParameters_IfActionParameterHasSwaggerIgnoreAttribute ( )
478+ {
479+ var subject = Subject (
480+ new [ ]
481+ {
482+ ApiDescriptionFactory . Create < FakeController > (
483+ c => nameof ( c . ActionWithIntParameterWithSwaggerIgnoreAttribute ) ,
484+ groupName : "v1" ,
485+ httpMethod : "POST" ,
486+ relativePath : "resource" ,
487+ parameterDescriptions : new [ ]
488+ {
489+ new ApiParameterDescription
490+ {
491+ Name = "param" ,
492+ Source = BindingSource . Query
493+ }
494+ }
495+ )
496+ }
497+ ) ;
498+
499+ var document = subject . GetSwagger ( "v1" ) ;
500+
501+ var operation = document . Paths [ "/resource" ] . Operations [ OperationType . Post ] ;
502+ Assert . Empty ( operation . Parameters ) ;
503+ }
504+
476505 [ Fact ]
477506 public void GetSwagger_SetsParameterRequired_IfApiParameterIsBoundToPath ( )
478507 {
You can’t perform that action at this time.
0 commit comments