- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
60 lines (49 loc) · 1.44 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
51
52
53
54
55
56
57
58
59
60
usingMicrosoft.Extensions.Options;
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddOpenApi();
builder.Services.AddOpenApiDocument();
varapp=builder.Build();
app.MapOpenApi("/openapi/{documentName}.json");
app.MapOpenApi("/openapi/{documentName}.yaml");
app.UseSwaggerUi(options =>
{
options.DocumentPath="/openapi/{documentName}.yaml";
});
app.MapGet("/",()=>
{
varhtml="""
<html>
<body>
<h1>OpenAPI JSON/YAML documents</h1>
<ul>
<li>
You can check the generated OpenAPI document in JSON <a href="/openapi/v1.json">here</a>.
</li>
<li>
The OpenAPI document is also available in YAML format <a href="/openapi/v1.yaml">here</a>.
</li>
<li>
You can check the Swagger UI <a href="/swagger/index.html">here</a>.
</li>
</ul>
</body>
</html>
""";
returnTypedResults.Content(html,"text/html");
}).ExcludeFromDescription();//This is not an API endpoint
app.MapGet("/hello/{name}",Hello);
app.Run();
staticpartialclassProgram
{
///<summary>
/// Returns a greeting message
/// </summary>
/// <remarks>
/// This is a sample endpoint that returns a greeting message.
/// </remarks>
/// <param name="name">The name of the person to greet</param>
publicstaticstringHello(stringname)
{
return$"Hello, {name}";
}
}