question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extend SwaggerFilter

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Apr 25, 2020

Nope. You can replace IAbpSession.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found