Fixes the swagger ui access
All checks were successful
Dotnet build and test / build (pull_request) Successful in 12m25s

This commit is contained in:
Paul Schneider 2026-09-25 10:20:18 +01:00
commit a793996b70
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
2 changed files with 23 additions and 3 deletions

5
.gitignore vendored
View file

@ -44,5 +44,8 @@ DataDir/
*.log *.log
# gitleaks scan output (local secret-scan report, not for the repo) # gitleaks scan output (local secret-scan report, not for the repo)
gitleaks-report.json /gitleaks-report.json
/test-report.html
/test-report.xml

View file

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Yavsc.Models; using Yavsc.Models;
@ -19,7 +20,7 @@ namespace Yavsc.Controllers
public CommentsController(ApplicationDbContext context) public CommentsController(ApplicationDbContext context)
{ {
_context = context; _context = context;
} }
[HttpGet("{id:long}", Name = "GetComment")] [HttpGet("{id:long}", Name = "GetComment")]
@ -82,8 +83,17 @@ namespace Yavsc.Controllers
return CreatedAtRoute("GetComment", new { id = comment.Id }, new { id = comment.Id, dateCreated = comment.DateCreated }); return CreatedAtRoute("GetComment", new { id = comment.Id }, new { id = comment.Id, dateCreated = comment.DateCreated });
} }
// --- Actions MVC scaffoldées (vues CRUD) ---------------------
// Ces actions ne font pas partie de la surface d'API documentée
// par Swagger. Elles sont exclues de l'ApiExplorer : sinon, comme
// le contrôleur porte [Route("~/api/v1/blogcomments")], leurs
// [HttpPost] sans template propre atterrissent sur la même route
// "POST api/v1/blogcomments" que l'action Post ci-dessus, et
// Swashbuckle lève une SwaggerGeneratorException (conflicting
// method/path) au démarrage de /swagger.
// GET: Comments // GET: Comments
[HttpGet] [HttpGet]
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Index() public async Task<IActionResult> Index()
{ {
var applicationDbContext = _context.Comment.Include(c => c.Post); var applicationDbContext = _context.Comment.Include(c => c.Post);
@ -91,6 +101,7 @@ namespace Yavsc.Controllers
} }
// GET: Comments/Details/5 // GET: Comments/Details/5
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Details(long? id) public async Task<IActionResult> Details(long? id)
{ {
if (id == null) if (id == null)
@ -109,6 +120,7 @@ namespace Yavsc.Controllers
// GET: Comments/Create (MVC form endpoint) // GET: Comments/Create (MVC form endpoint)
[HttpGet("form")] [HttpGet("form")]
[ApiExplorerSettings(IgnoreApi = true)]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.ReceiverId = new SelectList(_context.BlogSpot, "Id", "Title"); ViewBag.ReceiverId = new SelectList(_context.BlogSpot, "Id", "Title");
@ -118,6 +130,7 @@ namespace Yavsc.Controllers
// POST: Comments/Create (MVC form endpoint) // POST: Comments/Create (MVC form endpoint)
[HttpPost("form")] [HttpPost("form")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Create(Comment comment) public async Task<IActionResult> Create(Comment comment)
{ {
comment.UserCreated = User.GetUserId(); comment.UserCreated = User.GetUserId();
@ -126,7 +139,7 @@ namespace Yavsc.Controllers
// remove the stale binding error so a valid authenticated POST // remove the stale binding error so a valid authenticated POST
// does not fall into the invalid branch. // does not fall into the invalid branch.
ModelState.Remove(nameof(Comment.AuthorId)); ModelState.Remove(nameof(Comment.AuthorId));
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
_context.Comment.Add(comment); _context.Comment.Add(comment);
@ -138,6 +151,7 @@ namespace Yavsc.Controllers
} }
// GET: Comments/Edit/5 // GET: Comments/Edit/5
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Edit(long? id) public async Task<IActionResult> Edit(long? id)
{ {
if (id == null) if (id == null)
@ -157,6 +171,7 @@ namespace Yavsc.Controllers
// POST: Comments/Edit/5 // POST: Comments/Edit/5
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Edit(Comment comment) public async Task<IActionResult> Edit(Comment comment)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
@ -171,6 +186,7 @@ namespace Yavsc.Controllers
// GET: Comments/Delete/5 // GET: Comments/Delete/5
[ActionName("Delete")] [ActionName("Delete")]
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> Delete(long? id) public async Task<IActionResult> Delete(long? id)
{ {
if (id == null) if (id == null)
@ -190,6 +206,7 @@ namespace Yavsc.Controllers
// POST: Comments/Delete/5 // POST: Comments/Delete/5
[HttpPost, ActionName("Delete")] [HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> DeleteConfirmed(long id) public async Task<IActionResult> DeleteConfirmed(long id)
{ {
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id); Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);