I try to add conditionally an OperationProcessor
in NSwag. For example, the DefaultApiValueOperationProcessor
should only be added/enabled when we are in a development environment (env.IsDevelopment
)
Unfortunately I can't retrieve IHostingEnvironment
in ConfigureServices
, and also I can't get the Swagger's OperationProcessors
on Configure
, see code example at the comment lines:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerDocument(s =>
{
// can't get IHostingEnvironment here? (for env.IsDevelopment())
s.OperationProcessors.Add(new DefaultApiValueOperationProcessor("version", "1"));
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// can't get Swagger's OperationProcessors here?
app.UseOpenApi();
app.UseSwaggerUi3(o =>
{
o.DocExpansion = "list";
o.DocumentTitle = "My API";
});
app.UseMvc();
}
}
Any idea how I could fix this?