Swagger

Recipes

  • packages
<PackageReference Include="Swashbuckle" Version="5.5.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
public class SwaggerTests
{
    private const string TargetUrl = "/swagger/v1.0/swagger.json";

    [Fact, IsWarmUp]
    public async Task VerifySwaggerEndpoint()
    {
        string swaggerResult;
        using (var client = new System.Net.WebClient())
        {
            swaggerResult = await client.DownloadStringTaskAsync($"{Settings.Instance.SiteURL}{TargetUrl}");
        }

        swaggerResult.Should().NotBeNull();

        var obj = JsonConvert.DeserializeObject<JObject>(swaggerResult);
        var paths = obj["paths"];
        Assert.True(paths.Children().Count() > 1);
    }
}
  • better name generation UI
    • Instead of [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(void))] use [SwaggerResponse(StatusCodes.Status401Unauthorized, null, "Unauthorized")].
    • Instead of [Action("name")] use SwaggerOperation("Ping", Schemes = new[] { "http" })].