samples/MongoDB.WebAPI/Swagger/Filters/SwaggerDefaultValues.cs
/// <summary>
/// Applies the filter to the specified operation using the given context.
/// </summary>
/// <param name="operation">The operation to apply the filter to.</param>
/// <param name="context">The current operation filter context.</param>
Applies the filter to the specified operation using the given context.
Applies the filter to the specified operation using the given context .
public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            var apiDescription = context.ApiDescription;
            operation.Deprecated |= apiDescription.IsDeprecated();
            if (operation.Parameters == null)
            {
                return;
            }
            foreach (var parameter in operation.Parameters)
            {
                var description = apiDescription.ParameterDescriptions.FirstOrDefault(p => string.Equals(p.Name, parameter.Name, StringComparison.OrdinalIgnoreCase));
                if (description == null)
                {
                    continue;
                }
                if (parameter.Description == null)
                {
                    parameter.Description = description.ModelMetadata?.Description;
                }
                if (parameter.Schema.Default == null && description.DefaultValue != null)
                {
                    parameter.Schema.Default = new OpenApiString(description.DefaultValue.ToString());
                }
                parameter.Required |= description.IsRequired;
            }
        }
public void Apply ( OpenApiOperation operation , OperationFilterContext context ) { var apiDescription = context . ApiDescription ; operation . Deprecated |= apiDescription . IsDeprecated ( ) ; if ( operation . Parameters == null ) { return ; } foreach ( var parameter in operation . Parameters ) { var description = apiDescription . ParameterDescriptions . FirstOrDefault ( p => string . Equals ( p . Name , parameter . Name , StringComparison . OrdinalIgnoreCase ) ) ; if ( description == null ) { continue ; } if ( parameter . Description == null ) { parameter . Description = description . ModelMetadata ? . Description ; } if ( parameter . Schema . Default == null && description . DefaultValue != null ) { parameter . Schema . Default = new OpenApiString ( description . DefaultValue . ToString ( ) ) ; } parameter . Required |= description . IsRequired ; } }
Applies the filter to the specified operation using the given context.
Applies the filter to the specified operation using the given context .
operation
OpenApiOperation
The operation to apply the filter to.
The operation to apply the filter to .
context
OperationFilterContext
The current operation filter context.
The current operation filter context .