Skip to content

Commit e8d7cfc

Browse files
committed
Added Swagger
1 parent 48b4d7e commit e8d7cfc

12 files changed

Lines changed: 36 additions & 9 deletions

File tree

plugins/Common/Widgets/Categories.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public async Task<IViewComponentResult> InvokeAsync(string theme, string widget)
4141
}
4242
}
4343

44+
[ApiExplorerSettings(IgnoreApi = true)]
4445
[Route("widgets/api/categories")]
4546
public class CategoriesController : Controller
4647
{

plugins/Common/Widgets/HtmlBlock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public IViewComponentResult Invoke(string theme, string widget)
3737
}
3838
}
3939

40+
[ApiExplorerSettings(IgnoreApi = true)]
4041
[Route("widgets/api/htmlblock")]
4142
public class HtmlBlockController : Controller
4243
{

plugins/Common/Widgets/Newsletter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ public IViewComponentResult Invoke(string theme, string widget)
3333
}
3434
}
3535

36+
[ApiExplorerSettings(IgnoreApi = true)]
3637
[Route("widgets/newsletter")]
3738
public class NewsletterController : Controller
3839
{
39-
IDataService _db;
40+
readonly IDataService _db;
4041

4142
public NewsletterController(IDataService db)
4243
{
4344
_db = db;
4445
}
4546

46-
[Route("load")]
47+
[HttpGet("load")]
4748
public async Task<NewsletterModel> Load(int page = 1)
4849
{
4950
var pager = new Pager(page);

plugins/Common/Widgets/PostList.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public IViewComponentResult Invoke(string theme, string widget)
6666
}
6767
}
6868

69+
[ApiExplorerSettings(IgnoreApi = true)]
6970
[Route("widgets/api/postlist")]
7071
public class PostListController : Controller
7172
{

src/App/App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.1" PrivateAssets="All" />
1313
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
1414
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
15+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
1516
</ItemGroup>
1617

1718
<ItemGroup>

src/App/Controllers/AdminController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace App.Controllers
99
{
1010
[Authorize]
11+
[ApiExplorerSettings(IgnoreApi = true)]
1112
public class AdminController : Controller
1213
{
1314
IDataService _db;

src/App/Controllers/BlogController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace App.Controllers
1515
{
16+
[ApiExplorerSettings(IgnoreApi = true)]
1617
public class BlogController : Controller
1718
{
1819
IDataService _db;
@@ -64,7 +65,7 @@ public async Task<IActionResult> Index(int page = 1, string term = "")
6465
return View(string.Format(_listView, blog.Theme), model);
6566
}
6667

67-
[Route("posts/{slug}")]
68+
[HttpGet("posts/{slug}")]
6869
public async Task<IActionResult> Single(string slug)
6970
{
7071
try
@@ -88,7 +89,7 @@ public async Task<IActionResult> Single(string slug)
8889

8990
}
9091

91-
[Route("authors/{name}")]
92+
[HttpGet("authors/{name}")]
9293
public async Task<IActionResult> Authors(string name, int page = 1)
9394
{
9495
var blog = await _db.CustomFields.GetBlogSettings();
@@ -114,7 +115,7 @@ public async Task<IActionResult> Authors(string name, int page = 1)
114115
return View(string.Format(_listView, model.Blog.Theme), model);
115116
}
116117

117-
[Route("categories/{name}")]
118+
[HttpGet("categories/{name}")]
118119
public async Task<IActionResult> Categories(string name, int page = 1)
119120
{
120121
var blog = await _db.CustomFields.GetBlogSettings();
@@ -139,7 +140,7 @@ public async Task<IActionResult> Categories(string name, int page = 1)
139140
return View(string.Format(_listView, model.Blog.Theme), model);
140141
}
141142

142-
[Route("feed/{type}")]
143+
[HttpGet("feed/{type}")]
143144
public async Task Rss(string type)
144145
{
145146
Response.ContentType = "application/xml";
@@ -163,7 +164,7 @@ public async Task Rss(string type)
163164
}
164165
}
165166

166-
[Route("error/{code:int}")]
167+
[HttpGet("error/{code:int}")]
167168
public async Task<IActionResult> Error(int code)
168169
{
169170
var model = new PostModel();

src/App/Startup.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public void ConfigureServices(IServiceCollection services)
102102
.AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly).AddControllersAsServices()
103103
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
104104

105+
services.AddSwaggerGen(setupAction => {
106+
setupAction.SwaggerDoc("spec",
107+
new Microsoft.OpenApi.Models.OpenApiInfo()
108+
{
109+
Title = "Blogifier API",
110+
Version = "1"
111+
});
112+
});
113+
105114
services.AddAppServices();
106115
}
107116

@@ -117,6 +126,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
117126
app.UseStaticFiles();
118127
app.UseRequestLocalization();
119128

129+
app.UseSwagger();
130+
app.UseSwaggerUI(setupAction =>
131+
{
132+
setupAction.SwaggerEndpoint(
133+
"/swagger/spec/swagger.json",
134+
"Blogifier API"
135+
);
136+
});
137+
120138
AppSettings.WebRootPath = env.WebRootPath;
121139
AppSettings.ContentRootPath = env.ContentRootPath;
122140

src/Core/Api/PostsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public PostsController(IDataService data)
2121
_data = data;
2222
}
2323

24+
[HttpGet]
2425
public async Task<ActionResult<PageListModel>> Get([FromQuery]string term = "", [FromQuery]string status = "", [FromQuery]int page = 1)
2526
{
2627
try

src/Core/Api/SettingsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public SettingsController(IDataService data, IOptions<RequestLocalizationOptions
2727
_options = options;
2828
}
2929

30-
[HttpGet("{cultures}")]
30+
[HttpGet("cultures")]
3131
public async Task<ActionResult<List<SelectListItem>>> GetCultures()
3232
{
3333
try

0 commit comments

Comments
 (0)