public void Apply(Operation operation, OperationFilterContext context) { var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors; var isAuthorized = filterPipeline.Select(filterInfo => filterInfo.Filter).Any(filter => filter is AuthorizeFilter); var allowAnonymous = filterPipeline.Select(filterInfo => filterInfo.Filter).Any(filter => filter is IAllowAnonymousFilter); if (isAuthorized && !allowAnonymous) { if (operation.Parameters == null) { operation.Parameters = new List<IParameter>(); } var tokenParameter = new NonBodyParameter { Type = "string", In = "header", Name = "Authorization", Description = "token", Default = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJsb2NhbGhvc3QiLCJhdXRob3JpdHkiOiJhdXRob3JpdHkiLCJmb28iOiJiYXIiLCJpc3MiOiJ3ZSB0aGUgbWFueSJ9.bm77vM2yQXc93vnc44Rqv_Rkm5OszFa9daM37db6EBg", Required = true }; operation.Parameters.Add(tokenParameter); } }
private IParameter CreateParameter( ApiDescription apiDescription, ApiParameterDescription paramDescription, ISchemaRegistry schemaRegistry) { var location = GetParameterLocation(apiDescription, paramDescription); var name = _settings.DescribeAllParametersInCamelCase ? paramDescription.Name.ToCamelCase() : paramDescription.Name; var schema = (paramDescription.Type == null) ? null : schemaRegistry.GetOrRegister(paramDescription.Type); if (location == "body") { return(new BodyParameter { Name = name, Schema = schema }); } var nonBodyParam = new NonBodyParameter { Name = name, In = location, Required = (location == "path") }; if (schema == null) { nonBodyParam.Type = "string"; } else { nonBodyParam.PopulateFrom(schema); } if (nonBodyParam.Type == "array") { nonBodyParam.CollectionFormat = "multi"; } return(nonBodyParam); }
private IParameter CreateParameter(ApiParameterDescription paramDesc, ISchemaRegistry schemaRegistry) { var source = paramDesc.Source.Id.ToLower(); var schema = (paramDesc.Type == null) ? null : schemaRegistry.GetOrRegister(paramDesc.Type); if (source == "body") { return(new BodyParameter { Name = paramDesc.Name, In = source, Schema = schema }); } else { var nonBodyParam = new NonBodyParameter { Name = paramDesc.Name, In = source, Required = (source == "path") }; if (schema == null) { nonBodyParam.Type = "string"; } else { nonBodyParam.PopulateFrom(schema); } if (nonBodyParam.Type == "array") { nonBodyParam.CollectionFormat = "multi"; } return(nonBodyParam); } }
private IParameter CreateParameter(ApiParameterDescription paramDesc, ISchemaRegistry schemaRegistry) { var source = paramDesc.Source.Id.ToLower(); var schema = (paramDesc.Type == null) ? null : schemaRegistry.GetOrRegister(paramDesc.Type); if (source == "body") { return new BodyParameter { Name = paramDesc.Name, In = source, Schema = schema }; } else { var nonBodyParam = new NonBodyParameter { Name = paramDesc.Name, In = source, Required = (source == "path") }; if (schema == null) nonBodyParam.Type = "string"; else nonBodyParam.PopulateFrom(schema); if (nonBodyParam.Type == "array") nonBodyParam.CollectionFormat = "multi"; return nonBodyParam; } }