Skip to content

Commit ea01473

Browse files
Add Swagger
1 parent d399455 commit ea01473

File tree

8 files changed

+180
-4
lines changed

8 files changed

+180
-4
lines changed

SwiftLink.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwiftLink.Domain", "src\Swi
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0143A2D3-97FF-4B41-B2C8-B482BF0508A5}"
99
ProjectSection(SolutionItems) = preProject
10+
changelog.md = changelog.md
1011
Dockerfile = Dockerfile
1112
LICENSE = LICENSE
1213
README.md = README.md
@@ -26,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwiftLink.Shared", "src\Swi
2627
EndProject
2728
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{19001328-2279-4C26-BC2B-C0AB9B07524E}"
2829
EndProject
29-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftLink.Application.UnitTests", "tests\SwiftLink.Application.UnitTests\SwiftLink.Application.UnitTests.csproj", "{B3286D3F-2DCC-4729-BE35-63C32886F8A5}"
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwiftLink.Application.UnitTests", "tests\SwiftLink.Application.UnitTests\SwiftLink.Application.UnitTests.csproj", "{B3286D3F-2DCC-4729-BE35-63C32886F8A5}"
3031
EndProject
3132
Global
3233
GlobalSection(SolutionConfigurationPlatforms) = preSolution

changelog.md

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"swashbuckle.aspnetcore.cli": {
6+
"version": "6.5.0",
7+
"commands": [
8+
"swagger"
9+
]
10+
}
11+
}
12+
}

src/SwiftLink.Presentation/Controllers/LinkController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
namespace SwiftLink.Presentation.Controllers;
88

9+
[Route("api/v{v:apiVersion}/[controller]/[action]")]
910
public class LinkController(ISender sender) : BaseController(sender)
1011
{
1112
[HttpPost]
12-
[Route("api/v{v:apiVersion}/[controller]/[action]")]
13+
public async Task<IActionResult> NewShorten([FromBody] GenerateShortCodeCommand command, CancellationToken cancellationToken = default)
14+
=> OK(await _mediarR.Send(command, cancellationToken));
15+
16+
[HttpPost]
1317
public async Task<IActionResult> Shorten([FromBody] GenerateShortCodeCommand command, CancellationToken cancellationToken = default)
1418
=> OK(await _mediarR.Send(command, cancellationToken));
1519

src/SwiftLink.Presentation/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using HealthChecks.UI.Client;
33
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.OpenApi.Models;
56
using Prometheus;
67
using SwiftLink.Application;
78
using SwiftLink.Infrastructure;
@@ -48,6 +49,19 @@
4849
{
4950
options.Port = ushort.Parse(builder.Configuration["AppSettings:DefaultPrometheusPort"]);
5051
});
52+
53+
builder.Services.AddSwaggerGen(c =>
54+
{
55+
c.SwaggerDoc("v1", new OpenApiInfo
56+
{
57+
Title = "SwiftLink",
58+
Version = "v1",
59+
});
60+
c.SwaggerGeneratorOptions.Servers =
61+
[
62+
new() { Url = "http://localhost:56453" }
63+
];
64+
});
5165
}
5266

5367
var app = builder.Build();

src/SwiftLink.Presentation/SwiftLink.Presentation.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
<PackageReference Include="prometheus-net" Version="8.2.1" />
2727
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
2828
<PackageReference Include="Serilog" Version="3.1.1" />
29-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
29+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
3030
</ItemGroup>
3131

3232
<ItemGroup>
3333
<ProjectReference Include="..\SwiftLink.Infrastructure\SwiftLink.Infrastructure.csproj" />
3434
</ItemGroup>
35-
3635
</Project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: 3.0.1
2+
info:
3+
title: SwiftLink
4+
version: v1
5+
servers:
6+
- url: https://localhost:5001
7+
paths:
8+
/api/v1/Link/Shorten:
9+
post:
10+
tags:
11+
- Link
12+
requestBody:
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/GenerateShortCodeCommand'
17+
text/json:
18+
schema:
19+
$ref: '#/components/schemas/GenerateShortCodeCommand'
20+
application/*+json:
21+
schema:
22+
$ref: '#/components/schemas/GenerateShortCodeCommand'
23+
responses:
24+
'200':
25+
description: Success
26+
'/api/{shortCode}':
27+
get:
28+
tags:
29+
- Link
30+
parameters:
31+
- name: shortCode
32+
in: path
33+
required: true
34+
schema:
35+
type: string
36+
- name: password
37+
in: query
38+
schema:
39+
type: string
40+
responses:
41+
'200':
42+
description: Success
43+
components:
44+
schemas:
45+
GenerateShortCodeCommand:
46+
type: object
47+
properties:
48+
url:
49+
type: string
50+
nullable: true
51+
description:
52+
type: string
53+
nullable: true
54+
expirationDate:
55+
type: string
56+
format: date-time
57+
nullable: true
58+
password:
59+
type: string
60+
nullable: true
61+
token:
62+
type: string
63+
format: uuid
64+
additionalProperties: false
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
openapi: 3.0.1
2+
info:
3+
title: SwiftLink
4+
version: v1
5+
servers:
6+
- url: http://localhost:56453
7+
paths:
8+
/api/v1/Link/NewShorten:
9+
post:
10+
tags:
11+
- Link
12+
requestBody:
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/GenerateShortCodeCommand'
17+
text/json:
18+
schema:
19+
$ref: '#/components/schemas/GenerateShortCodeCommand'
20+
application/*+json:
21+
schema:
22+
$ref: '#/components/schemas/GenerateShortCodeCommand'
23+
responses:
24+
'200':
25+
description: Success
26+
/api/v1/Link/Shorten:
27+
post:
28+
tags:
29+
- Link
30+
requestBody:
31+
content:
32+
application/json:
33+
schema:
34+
$ref: '#/components/schemas/GenerateShortCodeCommand'
35+
text/json:
36+
schema:
37+
$ref: '#/components/schemas/GenerateShortCodeCommand'
38+
application/*+json:
39+
schema:
40+
$ref: '#/components/schemas/GenerateShortCodeCommand'
41+
responses:
42+
'200':
43+
description: Success
44+
'/api/{shortCode}':
45+
get:
46+
tags:
47+
- Link
48+
parameters:
49+
- name: shortCode
50+
in: path
51+
required: true
52+
schema:
53+
type: string
54+
- name: password
55+
in: query
56+
schema:
57+
type: string
58+
responses:
59+
'200':
60+
description: Success
61+
components:
62+
schemas:
63+
GenerateShortCodeCommand:
64+
type: object
65+
properties:
66+
url:
67+
type: string
68+
nullable: true
69+
description:
70+
type: string
71+
nullable: true
72+
expirationDate:
73+
type: string
74+
format: date-time
75+
nullable: true
76+
password:
77+
type: string
78+
nullable: true
79+
token:
80+
type: string
81+
format: uuid
82+
additionalProperties: false

0 commit comments

Comments
 (0)