extend SwaggerFilter
See original GitHub issueI have an interfacee and class like this:
public interface IBsSession:IAbpSession
{
// some method declaration
}
public class BsSession : ClaimsAbpSession, IBsSession, ITransientDependency
{
private readonly ITerminalCache _terminalCache;
private readonly IHttpContextRequestItbs _contextRequest;
private readonly IRepository<Terminal, Guid> _terminalRepository;
public BsSession(ITerminalCache terminalCache,
IPrincipalAccessor principalAccessor, IMultiTenancyConfig multiTenancy, ITenantResolver tenantResolver,
IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider, IHttpContextRequestItbs contextRequest,
IRepository<Terminal, Guid> terminalRepository)
: base(principalAccessor, multiTenancy,
tenantResolver, sessionOverrideScopeProvider)
{
_terminalCache = terminalCache;
_contextRequest = contextRequest;
_terminalRepository = terminalRepository;
}
// implementation is here
}
and I have a filter:
public class TenantHeaderSwaggerFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<IParameter>();
operation.Parameters.Add(new NonBodyParameter
{
Name = "Abp.TenantId",
In = "header",
Type = "string",
Default = 7,
Required = false // set to false if this is optional
});
}
}
and modified swagger configuration like this:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Info { Title = "Messaging API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.DescribeAllEnumsAsStrings();
options.CustomSchemaIds(x => x.FullName);
//Define the BearerAuth scheme that's in use
options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = "header",
Type = "apiKey"
});
options.OperationFilter<TenantHeaderSwaggerFilter>();
});
Finally when I run the App, I see the Abp.TenantId in the swagger UI and I fill it and then press Execute. but the problem is when I inject IBsSession in any service, it throws internal server error and when I inject IAbpSession, the Abp.TenantId is not what I expected. I think there is a step missing. I don’t know where should I map Abp.TenantId (which I added into TenantHeaderSwaggerFilter class) to IAbpSession.TenantId or BsSession.TenantId .
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (18 by maintainers)
Top Results From Across the Web
Swagger - Extending SwaggerSpecFilter
I'm trying to write my own Swagger API Filter to hide certain things from appearing in the API. I think I have a...
Read more >Swagger UI Configuration
The top bar will show an edit box that you can use to filter the tagged operations ... Controls the display of vendor...
Read more >Swagger 2.X Extensions
Filters ; Configure a custom scanner; Extending Reader; Extending core Resolver. Reader listeners. You can provide the Swagger engine with a ...
Read more >Filter out x-vendor-extension in Swagger UI pane · Issue #74
There will be times where people will want to extend their API specs using x-vender-feature keys. Since these do not have meaning in...
Read more >Filtering Some Methods on Swagger By PermissionID on .Net ...
Blog: https://borakasmer.medium.com/ filtering -some-methods-on- swagger -by- ... NET Core - API Documentation : Swagger + Swashbuckle.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nope. You can replace
IAbpSession
.Please read the documentation: https://aspnetboilerplate.com/Pages/Documents/Startup-Configuration#replacing-built-in-services