From 4da75aa4ff452397db9ae73cfba37ba2ffd08f62 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 9 Jan 2020 21:05:44 -0500 Subject: [PATCH] Add ProducesResponseType for all controller actions - Excluding common status codes which will be documented elsewhere --- .../Controllers/AdministrationController.cs | 6 +++++ .../Controllers/ByondController.cs | 5 ++++ .../Controllers/ChatController.cs | 7 +++++ .../Controllers/ConfigurationController.cs | 27 +++++++++++++++++++ .../Controllers/DreamDaemonController.cs | 8 ++++++ .../Controllers/DreamMakerController.cs | 9 +++++++ .../Controllers/HomeController.cs | 4 +++ .../Controllers/InstanceController.cs | 13 +++++++-- .../Controllers/InstanceUserController.cs | 10 +++++++ .../Controllers/JobController.cs | 8 ++++++ .../Controllers/RepositoryController.cs | 9 ++++++- .../Controllers/UserController.cs | 9 +++++++ 12 files changed, 112 insertions(+), 3 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index 61198121f6..0cdf62a0a2 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -154,6 +154,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(Administration), 200)] + [ProducesResponseType(424)] + [ProducesResponseType(429)] public override async Task Read(CancellationToken cancellationToken) { try @@ -198,6 +201,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(AdministrationRights.ChangeVersion)] + [ProducesResponseType(typeof(ErrorMessage), 422)] public override async Task Update([FromBody] Administration model, CancellationToken cancellationToken) { if (model == null) @@ -224,6 +228,8 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the request [HttpDelete] [TgsAuthorize(AdministrationRights.RestartHost)] + [ProducesResponseType(200)] + [ProducesResponseType(typeof(ErrorMessage), 422)] public async Task Delete() { try diff --git a/src/Tgstation.Server.Host/Controllers/ByondController.cs b/src/Tgstation.Server.Host/Controllers/ByondController.cs index 10229aaef1..717fd136bb 100644 --- a/src/Tgstation.Server.Host/Controllers/ByondController.cs +++ b/src/Tgstation.Server.Host/Controllers/ByondController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; @@ -47,6 +48,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ByondRights.ReadActive)] + [ProducesResponseType(typeof(Api.Models.Byond), 200)] public override Task Read(CancellationToken cancellationToken) => Task.FromResult( Json(new Api.Models.Byond { @@ -55,6 +57,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ByondRights.ListInstalled)] + [ProducesResponseType(typeof(IEnumerable), 200)] public override Task List(CancellationToken cancellationToken) => Task.FromResult( Json(instanceManager.GetInstance(Instance).ByondManager.InstalledVersions.Select(x => new Api.Models.Byond { @@ -63,6 +66,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ByondRights.ChangeVersion)] + [ProducesResponseType(typeof(Api.Models.Byond), 200)] + [ProducesResponseType(typeof(Api.Models.Byond), 202)] public override async Task Update([FromBody] Api.Models.Byond model, CancellationToken cancellationToken) { if (model == null) diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 26ac8bc834..695fb0cd03 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -59,6 +59,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ChatBotRights.Create)] + [ProducesResponseType(typeof(Api.Models.ChatBot), 201)] public override async Task Create([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) { if (model == null) @@ -131,6 +132,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ChatBotRights.Delete)] + [ProducesResponseType(200)] public override async Task Delete(long id, CancellationToken cancellationToken) { var instance = instanceManager.GetInstance(Instance); @@ -141,6 +143,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ChatBotRights.Read)] + [ProducesResponseType(typeof(IEnumerable), 200)] public override async Task List(CancellationToken cancellationToken) { var query = DatabaseContext.ChatBots.Where(x => x.InstanceId == Instance.Id).Include(x => x.Channels); @@ -158,6 +161,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ChatBotRights.Read)] + [ProducesResponseType(typeof(Api.Models.ChatBot), 200)] + [ProducesResponseType(410)] public override async Task GetId(long id, CancellationToken cancellationToken) { var query = DatabaseContext.ChatBots.Where(x => x.Id == id).Include(x => x.Channels); @@ -177,6 +182,8 @@ namespace Tgstation.Server.Host.Controllers /// #pragma warning disable CA1506 // TODO: Decomplexify [TgsAuthorize(ChatBotRights.WriteChannels | ChatBotRights.WriteConnectionString | ChatBotRights.WriteEnabled | ChatBotRights.WriteName | ChatBotRights.WriteProvider)] + [ProducesResponseType(200)] + [ProducesResponseType(typeof(Api.Models.ChatBot), 200)] public override async Task Update([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) { if (model == null) diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index 49bbb78e67..b2849e30b7 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Threading; @@ -65,6 +66,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ConfigurationRights.Write)] + [ProducesResponseType(typeof(ConfigurationFile), 200)] + [ProducesResponseType(typeof(ConfigurationFile), 201)] + [ProducesResponseType(501)] public override async Task Update([FromBody] ConfigurationFile model, CancellationToken cancellationToken) { if (model == null) @@ -108,6 +112,9 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the for the operation [HttpGet(Routes.File + "/{*filePath}")] [TgsAuthorize(ConfigurationRights.Read)] + [ProducesResponseType(typeof(ConfigurationFile), 200)] + [ProducesResponseType(410)] + [ProducesResponseType(501)] public async Task File(string filePath, CancellationToken cancellationToken) { if (ForbidDueToModeConflicts(filePath, out var systemIdentity)) @@ -143,6 +150,9 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the for the operation [HttpGet("List/{*directoryPath}")] [TgsAuthorize(ConfigurationRights.List)] + [ProducesResponseType(typeof(IReadOnlyList), 200)] + [ProducesResponseType(410)] + [ProducesResponseType(501)] public async Task Directory(string directoryPath, CancellationToken cancellationToken) { if (ForbidDueToModeConflicts(directoryPath, out var systemIdentity)) @@ -168,10 +178,17 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(ConfigurationRights.List)] + [ProducesResponseType(typeof(IReadOnlyList), 200)] + [ProducesResponseType(410)] + [ProducesResponseType(501)] public override Task List(CancellationToken cancellationToken) => Directory(null, cancellationToken); /// [TgsAuthorize(ConfigurationRights.Write)] + [ProducesResponseType(typeof(ConfigurationFile), 200)] + [ProducesResponseType(typeof(ConfigurationFile), 201)] + [ProducesResponseType(410)] + [ProducesResponseType(501)] public override async Task Create([FromBody] ConfigurationFile model, CancellationToken cancellationToken) { if (model == null) @@ -185,6 +202,14 @@ namespace Tgstation.Server.Host.Controllers model.IsDirectory = true; return await instanceManager.GetInstance(Instance).Configuration.CreateDirectory(model.Path, systemIdentity, cancellationToken).ConfigureAwait(false) ? (IActionResult)Json(model) : StatusCode((int)HttpStatusCode.Created, model); } + catch (IOException e) + { + Logger.LogInformation("IOException while creating directory {0}: {1}", model.Path, e); + return Conflict(new ErrorMessage + { + Message = e.Message + }); + } catch (NotImplementedException) { return StatusCode((int)HttpStatusCode.NotImplemented); @@ -203,6 +228,8 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the operation [HttpDelete] [TgsAuthorize(ConfigurationRights.Delete)] + [ProducesResponseType(200)] + [ProducesResponseType(501)] public async Task Delete([FromBody] ConfigurationFile directory, CancellationToken cancellationToken) { if (directory == null) diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 3a33d10457..06994df6b6 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -51,6 +51,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamDaemonRights.Start)] + [ProducesResponseType(typeof(Api.Models.Job), 202)] + [ProducesResponseType(410)] public override async Task Create([FromBody] DreamDaemon model, CancellationToken cancellationToken) { // alias for launching DD @@ -73,6 +75,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)] + [ProducesResponseType(typeof(DreamDaemon), 200)] + [ProducesResponseType(410)] public override Task Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken); /// @@ -134,6 +138,7 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the operation [HttpDelete] [TgsAuthorize(DreamDaemonRights.Shutdown)] + [ProducesResponseType(200)] public async Task Delete(CancellationToken cancellationToken) { var instance = instanceManager.GetInstance(Instance); @@ -144,6 +149,8 @@ namespace Tgstation.Server.Host.Controllers /// #pragma warning disable CA1506 // TODO: Decomplexify [TgsAuthorize(DreamDaemonRights.SetAutoStart | DreamDaemonRights.SetPorts | DreamDaemonRights.SetSecurity | DreamDaemonRights.SetWebClient | DreamDaemonRights.SoftRestart | DreamDaemonRights.SoftShutdown | DreamDaemonRights.Start | DreamDaemonRights.SetStartupTimeout)] + [ProducesResponseType(typeof(DreamDaemon), 200)] + [ProducesResponseType(410)] public override async Task Update([FromBody] DreamDaemon model, CancellationToken cancellationToken) { if (model == null) @@ -219,6 +226,7 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the request [HttpPatch] [TgsAuthorize(DreamDaemonRights.Restart)] + [ProducesResponseType(typeof(Api.Models.Job), 202)] public async Task Restart(CancellationToken cancellationToken) { var job = new Models.Job diff --git a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs index f9d0a57451..af71b78151 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading; @@ -49,6 +50,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamMakerRights.Read)] + [ProducesResponseType(typeof(DreamMaker), 200)] public override async Task Read(CancellationToken cancellationToken) { var instance = instanceManager.GetInstance(Instance); @@ -58,6 +60,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamMakerRights.CompileJobs)] + [ProducesResponseType(typeof(Api.Models.CompileJob), 200)] + [ProducesResponseType(404)] public override async Task GetId(long id, CancellationToken cancellationToken) { var compileJob = await DatabaseContext.CompileJobs @@ -73,6 +77,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamMakerRights.CompileJobs)] + [ProducesResponseType(typeof(List), 200)] public override async Task List(CancellationToken cancellationToken) { var compileJobs = await DatabaseContext.CompileJobs.Where(x => x.Job.Instance.Id == Instance.Id).OrderByDescending(x => x.Job.StoppedAt).Select(x => new Api.Models.CompileJob @@ -84,6 +89,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamMakerRights.Compile)] + [ProducesResponseType(typeof(Api.Models.Job), 202)] public override async Task Create([FromBody] DreamMaker model, CancellationToken cancellationToken) { var job = new Models.Job @@ -100,6 +106,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(DreamMakerRights.SetDme | DreamMakerRights.SetApiValidationPort | DreamMakerRights.SetApiValidationPort)] + [ProducesResponseType(typeof(DreamMaker), 200)] + [ProducesResponseType(200)] + [ProducesResponseType(410)] public override async Task Update([FromBody] DreamMaker model, CancellationToken cancellationToken) { if (model.ApiValidationPort == 0) diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index 249f82f589..d5e61a062b 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -92,6 +92,7 @@ namespace Tgstation.Server.Host.Controllers [TgsAuthorize] [AllowAnonymous] [HttpGet] + [ProducesResponseType(typeof(Api.Models.ServerInformation), 200)] public IActionResult Home() { if (AuthenticationContext != null) @@ -117,6 +118,9 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation /// A resulting in the of the operation [HttpPost] + [ProducesResponseType(typeof(Api.Models.Token), 200)] + [ProducesResponseType(401)] + [ProducesResponseType(403)] #pragma warning disable CA1506 // TODO: Decomplexify public async Task CreateToken(CancellationToken cancellationToken) { diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 22419b3be2..c02dd7d936 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -110,6 +110,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceManagerRights.Create)] + [ProducesResponseType(typeof(Api.Models.Instance), 200)] + [ProducesResponseType(typeof(Api.Models.Instance), 201)] public override async Task Create([FromBody] Api.Models.Instance model, CancellationToken cancellationToken) { if (model == null) @@ -130,7 +132,7 @@ namespace Tgstation.Server.Host.Controllers }, out var normalizedLocalPath); if (rawPath.StartsWith(normalizedLocalPath, StringComparison.Ordinal)) - return Conflict("Instances cannot be created in the installation directory!"); + return Conflict(new ErrorMessage { Message = "Instances cannot be created in the installation directory!" }); var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken); bool attached = false; @@ -216,6 +218,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceManagerRights.Delete)] + [ProducesResponseType(200)] + [ProducesResponseType(410)] public override async Task Delete(long id, CancellationToken cancellationToken) { var originalModel = await DatabaseContext.Instances.Where(x => x.Id == id) @@ -250,7 +254,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceManagerRights.Relocate | InstanceManagerRights.Rename | InstanceManagerRights.SetAutoUpdate | InstanceManagerRights.SetConfiguration | InstanceManagerRights.SetOnline)] - #pragma warning disable CA1502 // TODO: Decomplexify + [ProducesResponseType(typeof(Api.Models.Instance), 200)] + [ProducesResponseType(410)] +#pragma warning disable CA1502 // TODO: Decomplexify public override async Task Update([FromBody] Api.Models.Instance model, CancellationToken cancellationToken) { var instanceQuery = DatabaseContext.Instances.Where(x => x.Id == model.Id); @@ -396,6 +402,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)] + [ProducesResponseType(typeof(IEnumerable), 200)] public override async Task List(CancellationToken cancellationToken) { IQueryable query = DatabaseContext.Instances; @@ -420,6 +427,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)] + [ProducesResponseType(typeof(Api.Models.Instance), 200)] + [ProducesResponseType(410)] public override async Task GetId(long id, CancellationToken cancellationToken) { var query = DatabaseContext.Instances.Where(x => x.Id == id); diff --git a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs index 67a4d0189d..2217e8f0e9 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading; @@ -48,6 +49,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceUserRights.CreateUsers)] + [ProducesResponseType(typeof(Api.Models.InstanceUser), 201)] public override async Task Create([FromBody] Api.Models.InstanceUser model, CancellationToken cancellationToken) { var test = StandardModelChecks(model); @@ -75,6 +77,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceUserRights.WriteUsers)] + [ProducesResponseType(typeof(Api.Models.InstanceUser), 200)] + [ProducesResponseType(410)] #pragma warning disable CA1506 // TODO: Decomplexify public override async Task Update([FromBody] Api.Models.InstanceUser model, CancellationToken cancellationToken) { @@ -104,10 +108,13 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(Api.Models.InstanceUser), 200)] + [ProducesResponseType(404)] public override Task Read(CancellationToken cancellationToken) => Task.FromResult(AuthenticationContext.InstanceUser != null ? (IActionResult)Json(AuthenticationContext.InstanceUser.ToApi()) : NotFound()); /// [TgsAuthorize(InstanceUserRights.ReadUsers)] + [ProducesResponseType(typeof(IEnumerable), 200)] public override async Task List(CancellationToken cancellationToken) { var users = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).SelectMany(x => x.InstanceUsers).ToListAsync(cancellationToken).ConfigureAwait(false); @@ -116,6 +123,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceUserRights.ReadUsers)] + [ProducesResponseType(typeof(Api.Models.InstanceUser), 200)] + [ProducesResponseType(410)] public override async Task GetId(long id, CancellationToken cancellationToken) { // this functions as userId @@ -127,6 +136,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(InstanceUserRights.WriteUsers)] + [ProducesResponseType(200)] public override async Task Delete(long id, CancellationToken cancellationToken) { await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).SelectMany(x => x.InstanceUsers).Where(x => x.UserId == id).DeleteAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index e5c08bbc99..c305597c4b 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading; @@ -38,6 +39,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(IEnumerable), 200)] public override async Task Read(CancellationToken cancellationToken) { var result = await DatabaseContext.Jobs.Where(x => x.Instance.Id == Instance.Id && !x.StoppedAt.HasValue).OrderByDescending(x => x.StartedAt).ToListAsync(cancellationToken).ConfigureAwait(false); @@ -46,6 +48,7 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(List), 200)] public override async Task List(CancellationToken cancellationToken) { // you KNOW this will need pagination eventually right? @@ -58,6 +61,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(202)] + [ProducesResponseType(404)] + [ProducesResponseType(410)] public override async Task Delete(long id, CancellationToken cancellationToken) { // don't care if an instance post or not at this point @@ -77,6 +83,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(404)] + [ProducesResponseType(typeof(Api.Models.Job), 200)] public override async Task GetId(long id, CancellationToken cancellationToken) { var job = await DatabaseContext.Jobs.Where(x => x.Id == id).Include(x => x.StartedBy).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 69d0d6417b..f08fa51e9d 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -128,6 +128,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(RepositoryRights.SetOrigin)] + [ProducesResponseType(typeof(Repository), 201)] + [ProducesResponseType(410)] public override async Task Create([FromBody] Repository model, CancellationToken cancellationToken) { if (model == null) @@ -219,6 +221,8 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation /// A resulting in the of the operation [TgsAuthorize(RepositoryRights.Delete)] + [ProducesResponseType(typeof(Repository), 202)] + [ProducesResponseType(410)] public async Task Delete(CancellationToken cancellationToken) { var currentModel = await DatabaseContext.RepositorySettings.Where(x => x.InstanceId == Instance.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); @@ -247,6 +251,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(RepositoryRights.Read)] + [ProducesResponseType(typeof(Repository), 200)] + [ProducesResponseType(typeof(Repository), 201)] + [ProducesResponseType(410)] public override async Task Read(CancellationToken cancellationToken) { var currentModel = await DatabaseContext.RepositorySettings.Where(x => x.InstanceId == Instance.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); @@ -273,7 +280,7 @@ namespace Tgstation.Server.Host.Controllers { if (repo != null && await PopulateApi(api, repo, DatabaseContext, Instance, cancellationToken).ConfigureAwait(false)) { - // user may have fucked with the repo without telling us, do what we can + // user may have fucked with the repo manually, do what we can await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); return StatusCode((int)HttpStatusCode.Created, api); } diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index d0fb649305..ebe9aaf2b3 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -75,6 +75,9 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(AdministrationRights.WriteUsers)] + [ProducesResponseType(typeof(Api.Models.User), 201)] + [ProducesResponseType(410)] + [ProducesResponseType(501)] public override async Task Create([FromBody] UserUpdate model, CancellationToken cancellationToken) { if (model == null) @@ -139,6 +142,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize(AdministrationRights.WriteUsers | AdministrationRights.EditOwnPassword)] + [ProducesResponseType(typeof(Api.Models.User), 200)] + [ProducesResponseType(404)] public override async Task Update([FromBody] UserUpdate model, CancellationToken cancellationToken) { if (model == null) @@ -187,10 +192,12 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(Api.Models.User), 200)] public override Task Read(CancellationToken cancellationToken) => Task.FromResult(Json(AuthenticationContext.User.ToApi(true))); /// [TgsAuthorize(AdministrationRights.ReadUsers)] + [ProducesResponseType(typeof(IEnumerable), 200)] public override async Task List(CancellationToken cancellationToken) { var users = await DatabaseContext.Users @@ -201,6 +208,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] + [ProducesResponseType(typeof(Api.Models.User), 200)] + [ProducesResponseType(404)] public override async Task GetId(long id, CancellationToken cancellationToken) { if (id == AuthenticationContext.User.Id)