Skip to content

Commit 1ab34ae

Browse files
committed
Build framework-specific swagger in test websites
The previous implementation caused the concurrent builds for various frameworks to compete in writing to the output `swagger.json` file, causing exceptions during builds (since it happened in csproj). In my local development I often failed to rebuild the full solution because some projects failed to build for this reason. It has also happened in CI (domaindrivendev#2886). Note that the NSwag source code generator in `NswagClientExample` still outputs everything in one spot for all frameworks, but I haven't noticed failures from that. Maybe it's just less likely to write concurrently. I left it as is.
1 parent d793865 commit 1ab34ae

File tree

13 files changed

+366
-10
lines changed

13 files changed

+366
-10
lines changed

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
3-
"version": "8.0.300",
4-
"allowPrerelease": false,
3+
"version": "8.0.300-preview.24203.14",
4+
"allowPrerelease": true,
55
"rollForward": "latestMajor"
66
}
77
}

test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SwaggerIntegrationTests
2020
{
2121
[Theory]
2222
[InlineData(typeof(Basic.Startup), "/swagger/v1/swagger.json")]
23-
[InlineData(typeof(CliExample.Startup), "/swagger/v1/swagger.json")]
23+
[InlineData(typeof(CliExample.Startup), "/swagger/v1/swagger_net8.0.json")]
2424
[InlineData(typeof(ConfigFromFile.Startup), "/swagger/v1/swagger.json")]
2525
[InlineData(typeof(CustomUIConfig.Startup), "/swagger/v1/swagger.json")]
2626
[InlineData(typeof(CustomUIIndex.Startup), "/swagger/v1/swagger.json")]

test/WebSites/CliExample/CliExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-->
2929

3030
<Target Name="SwaggerToFile" AfterTargets="AfterBuild">
31-
<Exec Command="dotnet dotnet-swagger.dll tofile --host http://localhost:51071 --output %22$(MSBuildThisFileDirectory)wwwroot/swagger/v1/swagger.json%22 %22$(OutputPath)$(AssemblyName).dll%22 v1"
31+
<Exec Command="dotnet dotnet-swagger.dll tofile --host http://localhost:51071 --output %22$(MSBuildThisFileDirectory)wwwroot/swagger/v1/swagger_$(TargetFramework).json%22 %22$(OutputPath)$(AssemblyName).dll%22 v1"
3232
WorkingDirectory="$(DotNetSwaggerPath)" />
3333
</Target>
3434

test/WebSites/CliExample/wwwroot/swagger/v1/swagger.json renamed to test/WebSites/CliExample/wwwroot/swagger/v1/swagger_net6.0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
}
5252
}
5353
}
54-
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "CliExample",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost:51071"
10+
}
11+
],
12+
"paths": {
13+
"/products": {
14+
"get": {
15+
"tags": [
16+
"Products"
17+
],
18+
"responses": {
19+
"200": {
20+
"description": "OK",
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "array",
25+
"items": {
26+
"$ref": "#/components/schemas/Product"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Product": {
39+
"type": "object",
40+
"properties": {
41+
"id": {
42+
"type": "integer",
43+
"format": "int32"
44+
},
45+
"description": {
46+
"type": "string",
47+
"nullable": true
48+
}
49+
},
50+
"additionalProperties": false
51+
}
52+
}
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "CliExample",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost:51071"
10+
}
11+
],
12+
"paths": {
13+
"/products": {
14+
"get": {
15+
"tags": [
16+
"Products"
17+
],
18+
"responses": {
19+
"200": {
20+
"description": "OK",
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "array",
25+
"items": {
26+
"$ref": "#/components/schemas/Product"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Product": {
39+
"type": "object",
40+
"properties": {
41+
"id": {
42+
"type": "integer",
43+
"format": "int32"
44+
},
45+
"description": {
46+
"type": "string",
47+
"nullable": true
48+
}
49+
},
50+
"additionalProperties": false
51+
}
52+
}
53+
}
54+
}

test/WebSites/CliExampleWithFactory/CliExampleWithFactory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
-->
3333

3434
<Target Name="SwaggerToFile" AfterTargets="AfterBuild">
35-
<Exec Command="dotnet dotnet-swagger.dll tofile --host http://localhost:57556/ --output %22$(MSBuildThisFileDirectory)wwwroot/swagger/v1/swagger.json%22 %22$(OutputPath)$(AssemblyName).dll%22 v1"
35+
<Exec Command="dotnet dotnet-swagger.dll tofile --host http://localhost:57556/ --output %22$(MSBuildThisFileDirectory)wwwroot/swagger/v1/swagger_$(TargetFramework).json%22 %22$(OutputPath)$(AssemblyName).dll%22 v1"
3636
WorkingDirectory="$(DotNetSwaggerPath)" />
3737
</Target>
3838

test/WebSites/CliExampleWithFactory/wwwroot/swagger/v1/swagger.json renamed to test/WebSites/CliExampleWithFactory/wwwroot/swagger/v1/swagger_net6.0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
}
5252
}
5353
}
54-
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "CliExampleWithFactory",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost:57556/"
10+
}
11+
],
12+
"paths": {
13+
"/products": {
14+
"get": {
15+
"tags": [
16+
"Products"
17+
],
18+
"responses": {
19+
"200": {
20+
"description": "OK",
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "array",
25+
"items": {
26+
"$ref": "#/components/schemas/Product"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Product": {
39+
"type": "object",
40+
"properties": {
41+
"id": {
42+
"type": "integer",
43+
"format": "int32"
44+
},
45+
"description": {
46+
"type": "string",
47+
"nullable": true
48+
}
49+
},
50+
"additionalProperties": false
51+
}
52+
}
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "CliExampleWithFactory",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost:57556/"
10+
}
11+
],
12+
"paths": {
13+
"/products": {
14+
"get": {
15+
"tags": [
16+
"Products"
17+
],
18+
"responses": {
19+
"200": {
20+
"description": "OK",
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "array",
25+
"items": {
26+
"$ref": "#/components/schemas/Product"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"Product": {
39+
"type": "object",
40+
"properties": {
41+
"id": {
42+
"type": "integer",
43+
"format": "int32"
44+
},
45+
"description": {
46+
"type": "string",
47+
"nullable": true
48+
}
49+
},
50+
"additionalProperties": false
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)