forked from dodyg/practical-aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
50 lines (44 loc) · 1.37 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(setup => setup.SwaggerDoc("v1", new OpenApiInfo()
{
Description = "A sample for demonstrating using .WithOpenApi() with Minimal API",
Title = "WithOpenApi()",
Version = "v1",
Contact = new OpenApiContact()
{
Name = "Practical ASP.NET Core",
Url = new Uri("https://github.com/dodyg/practical-aspnetcore")
}
}));
var app = builder.Build();
app.UseSwagger();
app.MapGet("/", () => Results.Content("""
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<div class="container">
<ul>
<li><a href="/swagger/index.html">Swagger Doc</a></li>
</ul>
</div>
</body>
</html>
""", "text/html"));
app.MapGet("/greeting", Hello.GetGreeting).WithOpenApi(op =>
{
op.OperationId = "GetGreetings";
op.Summary = "Return greeting given name";
return op;
});
app.UseSwaggerUI();
app.Run();
public record Person(string Name);
public static class Hello
{
public static IResult GetGreeting(string name) => Results.Ok(new Person(name));
}