Skip to content

Commit

Permalink
Support for non-nullable strings in Swagger (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
RPM1984 authored May 11, 2020
1 parent ae7b7ce commit 189d549
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions tests/TestWebApplication/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public TestController(IFakeVehicleRepository fakeVehicleRepository)

// GET: /test/1 | 200 OK.
[HttpGet("{id:int}", Name = "GetId")]
public IActionResult Get(int id)
public ActionResult<FakeVehicle> Get(int id)
{
var model = _fakeVehicleRepository.Get(id);

return model == null
? (IActionResult)NotFound()
? (ActionResult<FakeVehicle>) NotFound()
: Ok(model);
}

Expand Down
7 changes: 6 additions & 1 deletion tests/TestWebApplication/Models/FakeVehicle.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace TestWebApplication.Models
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;

namespace TestWebApplication.Models
{
public class FakeVehicle
{
public int Id { get; set; }

[Required]
public string Name { get; set; }
public string RegistrationNumber { get; set; }
public ColourType Colour { get; set; }
Expand Down

0 comments on commit 189d549

Please sign in to comment.