Enable swagger with flag
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
c0c1e7ca94
commit
7e7ecaf65a
@ -14,15 +14,21 @@ builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
string connectionString = builder.Configuration.GetConnectionString("DocumentDbConnection");
|
||||
string databaseName = builder.Configuration["DocumentDbName"] ?? "BackendMongoDb";
|
||||
string collectionName = builder.Configuration["DocumentCollectionName"] ?? "ToDos";
|
||||
string databaseName = builder.Configuration.GetConnectionString("DocumentDbName") ?? "BackendMongoDb";
|
||||
string collectionName = builder.Configuration.GetConnectionString("DocumentCollectionName") ?? "ToDos";
|
||||
|
||||
builder.Services.AddTransient<MongoClient>((_provider) => new MongoClient(connectionString));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
var isSwaggerEnabledFromConfig = bool.TrueString.Equals(builder.Configuration["EnableSwagger"] ?? "", StringComparison.OrdinalIgnoreCase);
|
||||
if (isSwaggerEnabledFromConfig)
|
||||
{
|
||||
Console.WriteLine("Swagger enabled via appsettings.json");
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
if (app.Environment.IsDevelopment() || isSwaggerEnabledFromConfig)
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
@ -50,7 +56,6 @@ app.MapGet("/api/todos/{id}", async (string id, MongoClient connection) =>
|
||||
{
|
||||
var database = connection.GetDatabase(databaseName);
|
||||
var collection = database.GetCollection<ToDo>(collectionName);
|
||||
|
||||
var result = await collection.FindAsync(record => record.Id == id).ConfigureAwait(false) as ToDo;
|
||||
|
||||
if (result is null)
|
||||
|
@ -6,8 +6,9 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DocumentDbConnection": "mongodb://mongo:27017"
|
||||
"DocumentDbConnection": "mongodb://mongo:27017",
|
||||
"DocumentDbName": "BackendMongoDb",
|
||||
"DocumentCollectionName": "ToDos"
|
||||
},
|
||||
"DocumentDbName": "BackendMongoDb",
|
||||
"DocumentCollectionName": "ToDos2"
|
||||
"EnableSwagger": "false"
|
||||
}
|
@ -23,6 +23,7 @@ services:
|
||||
- mongo
|
||||
environment:
|
||||
- ASPNETCORE_URLS=http://+:8000
|
||||
- EnableSwagger=true
|
||||
networks:
|
||||
- react-backend
|
||||
- react-frontend
|
||||
|
Loading…
Reference in New Issue
Block a user