Skip to content

Commit

Permalink
fix: Improve Swagger documentation (#4652)
Browse files Browse the repository at this point in the history
* Upgrade Swashbuckle dependency

* Document /token response

* Add support for Newtonsoft annotations in Swagger

* Remove unecessary ActionResult [skip ci]
  • Loading branch information
sephrat authored May 27, 2022
1 parent ae430e7 commit 181892b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Ombi.Api.Plex/Models/Metadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Ombi.Api.Plex.Models
{
Expand Down Expand Up @@ -38,6 +39,9 @@ public class Metadata
public string grandparentTheme { get; set; }
public string chapterSource { get; set; }
public Medium[] Media { get; set; }


[JsonProperty("guids")]
public List<PlexGuids> Guid { get; set; } = new List<PlexGuids>();
}

Expand Down
18 changes: 15 additions & 3 deletions src/Ombi/Controllers/V1/TokenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@
using Ombi.Store.Repository;
using Ombi.Core.Settings;
using Ombi.Settings.Settings.Models;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Ombi.Controllers.V1
{


public class Token
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
public DateTime Expiration { get; set; }
}

[ApiV1]
[Produces("application/json")]
[ApiController]
Expand Down Expand Up @@ -47,6 +58,7 @@ public TokenController(OmbiUserManager um, ITokenRepository token,
/// <returns></returns>
[HttpPost]
[ProducesResponseType(401)]
[ProducesResponseType(typeof(Token), 200)]
public async Task<IActionResult> GetToken([FromBody] UserAuthModel model)
{
if (!model.UsePlexOAuth)
Expand Down Expand Up @@ -161,10 +173,10 @@ private async Task<IActionResult> CreateToken(bool rememberMe, OmbiUser user)

await _userManager.UpdateAsync(user);

return new JsonResult(new
return Ok(new Token
{
access_token = accessToken,
expiration = token.ValidTo
AccessToken = accessToken,
Expiration = token.ValidTo
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/Ombi/Extensions/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public static void AddSwagger(this IServiceCollection services)
c.DescribeAllParametersInCamelCase();
});

services.AddSwaggerGenNewtonsoftSupport();
}

public static void AddAppSettingsValues(this IServiceCollection services, IConfigurationRoot configuration)
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi/Ombi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.3.1" />
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.0" />
Expand Down

0 comments on commit 181892b

Please sign in to comment.