add users documents
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
using Blahblah.FlowerStory.Server.Controller;
|
||||
using Blahblah.FlowerStory.Server.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace Blahblah.FlowerStory.Server;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public class Program
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public const string ProjectName = "Flower Story";
|
||||
/// <inheritdoc/>
|
||||
public const string Version = "0.23.523";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -15,17 +23,32 @@ public class Program
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.OperationFilter<SwaggerHttpHeaderOperation>();
|
||||
|
||||
options.SwaggerDoc(Version, new OpenApiInfo
|
||||
{
|
||||
Title = ProjectName,
|
||||
Version = Version,
|
||||
Description = "<p>花事记录,贴心的帮您记录花园中的点点滴滴。</p><p><b>API 文档</b></p>"
|
||||
});
|
||||
|
||||
options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Server.xml"));
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<FlowerDatabase>(options => options.UseSqlite("DataSource=flower.db;Cache=Shared"));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
//if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint($"/swagger/{Version}/swagger.json", ProjectName);
|
||||
});
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
@@ -33,4 +56,20 @@ public class Program
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public class SwaggerHttpHeaderOperation : IOperationFilter
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
operation.Parameters.Add(new OpenApiParameter
|
||||
{
|
||||
Name = "X-Auth",
|
||||
In = ParameterLocation.Header,
|
||||
Required = false,
|
||||
Schema = new OpenApiSchema { Type = "string" }
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user