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.

Configuration via appsettings.json

See original GitHub issue

Well, 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:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Salengo-comcommented, Aug 17, 2022

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>()));

0reactions
DeepakkSHAWcommented, Aug 31, 2022

The only addition is to fetch the IConfiguration instance before AddSwaggerGet

    var provider = services.BuildServiceProvider();
    var configuration = provider.GetRequiredService<IConfiguration>();
Read more comments on GitHub >

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

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