Configuration via appsettings.json
See original GitHub issueWell, it’s not a issue, just a basic question.
My swashbuckle configuration keeps growing.
I moved everything to the appsettings.json.
But now in StartUp.cs I have a lot of code like:
` options.SwaggerDoc ( Configuration[“SwaggerConfig:DocSettings:Name”], new Swashbuckle.AspNetCore.Swagger.Info { Title = Configuration[“SwaggerConfig:DocSettings:Info:Title”], Version = Configuration[“SwaggerConfig:DocSettings:Info:Version”], Description = Configuration[“SwaggerConfig:DocSettings:Info:Description”], TermsOfService = Configuration[“SwaggerConfig:DocSettings:Info:TermsOfService”],
Contact = new Swashbuckle.AspNetCore.Swagger.Contact()
{
Name = Configuration["SwaggerConfig:DocSettings:Info:Contact:Name"],
Email = Configuration["SwaggerConfig:DocSettings:Info:Contact:Email"],
Url = Configuration["SwaggerConfig:DocSettings:Info:Contact:Url"]
}
}
); `
Is there some more elegant / automatic way to configure swashbuckle via the appsettings.json? The code above does not check if the values are in the settings file.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
Configuration in ASP.NET Core
Using the default configuration, the appsettings.json and appsettings.{Environment}.json files are enabled with reloadOnChange: true. Changes ...
Read more >ASP.NET Core AppSettings.json file
The appsettings.json file is the application configuration file that is used to store configuration settings such as database connection strings, any ...
Read more >Application Settings (appsettings.json)
All of the application's settings are contained in a file named appsettings.json. Any changes to the appsettings.json file will require ...
Read more >How to read AppSettings values from a .json file in ASP. ...
using Microsoft.Extensions.Configuration;. In your code: VAR 1: var AppName = new ConfigurationBuilder().AddJsonFile("appsettings.json").
Read more >All About AppSettings In ASP.NET Core
Select the appsettings.json file and add the configuration settings. Here i have added two configuration settings "ConnectionStrings" and " ...
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 Free
Top 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
In case somesome wants to use appsettings.json to inject Openinfo directly, simply use :
services.AddSwaggerGen(options => options.SwaggerDoc("v1", configuration.GetSection("Swagger").Get<OpenApiInfo>()));
The only addition is to fetch the IConfiguration instance before AddSwaggerGet