Skip to content

Commit 13b172d

Browse files
committed
Add oas generation
1 parent 8f352ad commit 13b172d

File tree

4 files changed

+171
-10
lines changed

4 files changed

+171
-10
lines changed

oas/Api.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "DummyWebApiDemo",
5+
"version": "1"
6+
},
7+
"paths": {
8+
"/api/v1/dummies/{dummyId}": {
9+
"get": {
10+
"tags": [
11+
"Dummies"
12+
],
13+
"parameters": [
14+
{
15+
"name": "dummyId",
16+
"in": "path",
17+
"required": true,
18+
"style": "simple",
19+
"schema": {
20+
"type": "string"
21+
}
22+
}
23+
],
24+
"responses": {
25+
"200": {
26+
"description": "Success"
27+
}
28+
}
29+
}
30+
},
31+
"/api/v1/dummies": {
32+
"post": {
33+
"tags": [
34+
"Dummies"
35+
],
36+
"requestBody": {
37+
"content": {
38+
"application/json": {
39+
"schema": {
40+
"$ref": "#/components/schemas/CreateDummyRequest"
41+
}
42+
}
43+
}
44+
},
45+
"responses": {
46+
"200": {
47+
"description": "Success"
48+
}
49+
}
50+
}
51+
}
52+
},
53+
"components": {
54+
"schemas": {
55+
"CreateDummyRequest": {
56+
"type": "object",
57+
"properties": {
58+
"name": {
59+
"type": "string"
60+
}
61+
},
62+
"additionalProperties": false
63+
}
64+
}
65+
}
66+
}

oas/Api_v2.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "DummyWebApiDemo",
5+
"version": "2"
6+
},
7+
"paths": {
8+
"/api/v2/dummies": {
9+
"get": {
10+
"tags": [
11+
"Dummies"
12+
],
13+
"responses": {
14+
"200": {
15+
"description": "Success"
16+
}
17+
}
18+
},
19+
"post": {
20+
"tags": [
21+
"Dummies"
22+
],
23+
"requestBody": {
24+
"content": {
25+
"application/json": {
26+
"schema": {
27+
"$ref": "#/components/schemas/CreateDummyRequest"
28+
}
29+
}
30+
}
31+
},
32+
"responses": {
33+
"200": {
34+
"description": "Success"
35+
}
36+
}
37+
}
38+
},
39+
"/api/v2/dummies/search": {
40+
"get": {
41+
"tags": [
42+
"Dummies"
43+
],
44+
"parameters": [
45+
{
46+
"name": "Keyword",
47+
"in": "query",
48+
"style": "form",
49+
"schema": {
50+
"type": "string"
51+
}
52+
}
53+
],
54+
"responses": {
55+
"200": {
56+
"description": "Success"
57+
}
58+
}
59+
}
60+
},
61+
"/api/v2/dummies/{dummyId}": {
62+
"get": {
63+
"tags": [
64+
"Dummies"
65+
],
66+
"parameters": [
67+
{
68+
"name": "dummyId",
69+
"in": "path",
70+
"required": true,
71+
"style": "simple",
72+
"schema": {
73+
"type": "string"
74+
}
75+
}
76+
],
77+
"responses": {
78+
"200": {
79+
"description": "Success"
80+
}
81+
}
82+
}
83+
}
84+
},
85+
"components": {
86+
"schemas": {
87+
"CreateDummyRequest": {
88+
"type": "object",
89+
"properties": {
90+
"name": {
91+
"type": "string"
92+
}
93+
},
94+
"additionalProperties": false
95+
}
96+
}
97+
}
98+
}

src/Api/Api.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<OpenApiDocumentsDirectory>$(SolutionDir)\oas</OpenApiDocumentsDirectory>
8+
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
9+
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
710
</PropertyGroup>
811

912
<ItemGroup>
@@ -14,6 +17,10 @@
1417
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1518
<PrivateAssets>all</PrivateAssets>
1619
</PackageReference>
20+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="8.0.3">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
1724
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
1825
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
1926
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

src/Api/Extensions/SwaggerExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,12 @@ public static class SwaggerExtensions
1010
{
1111
public static void AddSwaggerDoc(this WebApplicationBuilder builder)
1212
{
13-
if (builder.Environment.IsProduction())
14-
{
15-
return;
16-
}
17-
1813
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
1914
builder.Services.AddSwaggerGen();
2015
}
2116

2217
public static void UseSwaggerDoc(this WebApplication app)
2318
{
24-
if (app.Environment.IsProduction())
25-
{
26-
return;
27-
}
28-
2919
app.UseSwagger();
3020
app.UseSwaggerUI(options =>
3121
{

0 commit comments

Comments
 (0)