Skip to content

Commit 5953d38

Browse files
updated and made swagger work finally
1 parent 9173795 commit 5953d38

22 files changed

+89
-98
lines changed

SampleWebApiAspNetCore.sln

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26206.0
4+
VisualStudioVersion = 15.0.27703.2026
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7E300EF-0B6D-46B2-8570-B1FA8A43FC11}"
7-
EndProject
8-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E6D256BA-07C1-4A30-96DF-01491A8D5952}"
9-
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApiAspNetCore", "src\SampleWebApiAspNetCore\SampleWebApiAspNetCore.csproj", "{34EBD18E-514B-4226-9069-3F3B0517B359}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApiAspNetCore", "SampleWebApiAspNetCore\SampleWebApiAspNetCore.csproj", "{62E0EE7C-8CF6-4E04-B3A1-49A19DE3FC75}"
117
EndProject
128
Global
139
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1410
Debug|Any CPU = Debug|Any CPU
1511
Release|Any CPU = Release|Any CPU
1612
EndGlobalSection
1713
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18-
{34EBD18E-514B-4226-9069-3F3B0517B359}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19-
{34EBD18E-514B-4226-9069-3F3B0517B359}.Debug|Any CPU.Build.0 = Debug|Any CPU
20-
{34EBD18E-514B-4226-9069-3F3B0517B359}.Release|Any CPU.ActiveCfg = Release|Any CPU
21-
{34EBD18E-514B-4226-9069-3F3B0517B359}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{62E0EE7C-8CF6-4E04-B3A1-49A19DE3FC75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{62E0EE7C-8CF6-4E04-B3A1-49A19DE3FC75}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{62E0EE7C-8CF6-4E04-B3A1-49A19DE3FC75}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{62E0EE7C-8CF6-4E04-B3A1-49A19DE3FC75}.Release|Any CPU.Build.0 = Release|Any CPU
2218
EndGlobalSection
2319
GlobalSection(SolutionProperties) = preSolution
2420
HideSolutionNode = FALSE
2521
EndGlobalSection
26-
GlobalSection(NestedProjects) = preSolution
27-
{34EBD18E-514B-4226-9069-3F3B0517B359} = {F7E300EF-0B6D-46B2-8570-B1FA8A43FC11}
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {34868541-E39B-446C-935B-C0F838B5DEC3}
2824
EndGlobalSection
2925
EndGlobal

src/SampleWebApiAspNetCore/Controllers/FoodsController.cs renamed to SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using SampleWebApiAspNetCore.Models;
1111
using SampleWebApiAspNetCore.Helpers;
1212

13-
namespace SampleWebApiAspNetCore.Controllers
13+
namespace SampleWebApiAspNetCore.v1.Controllers
1414
{
1515
[ApiVersion("1.0")]
1616
[Route("api/v{version:apiVersion}/[controller]")]
@@ -28,7 +28,7 @@ public FoodsController(IUrlHelper urlHelper, IFoodRepository foodRepository)
2828
}
2929

3030
[HttpGet(Name = nameof(GetAllFoods))]
31-
public IActionResult GetAllFoods([FromQuery] QueryParameters queryParameters)
31+
public ActionResult<object> GetAllFoods([FromQuery] QueryParameters queryParameters)
3232
{
3333
List<FoodItem> foodItems = _foodRepository.GetAll(queryParameters).ToList();
3434

@@ -58,7 +58,7 @@ public IActionResult GetAllFoods([FromQuery] QueryParameters queryParameters)
5858

5959
[HttpGet]
6060
[Route("{id:int}", Name = nameof(GetSingleFood))]
61-
public IActionResult GetSingleFood(int id)
61+
public ActionResult<OkObjectResult> GetSingleFood(int id)
6262
{
6363
FoodItem foodItem = _foodRepository.GetSingle(id);
6464

@@ -71,7 +71,7 @@ public IActionResult GetSingleFood(int id)
7171
}
7272

7373
[HttpPost(Name = nameof(AddFood))]
74-
public IActionResult AddFood([FromBody] FoodCreateDto foodCreateDto)
74+
public ActionResult<CreatedAtRouteResult> AddFood([FromBody] FoodCreateDto foodCreateDto)
7575
{
7676
if (foodCreateDto == null)
7777
{
@@ -99,7 +99,7 @@ public IActionResult AddFood([FromBody] FoodCreateDto foodCreateDto)
9999
}
100100

101101
[HttpPatch("{id:int}", Name = nameof(PartiallyUpdateFood))]
102-
public IActionResult PartiallyUpdateFood(int id, [FromBody] JsonPatchDocument<FoodUpdateDto> patchDoc)
102+
public ActionResult<OkObjectResult> PartiallyUpdateFood(int id, [FromBody] JsonPatchDocument<FoodUpdateDto> patchDoc)
103103
{
104104
if (patchDoc == null)
105105
{
@@ -136,7 +136,7 @@ public IActionResult PartiallyUpdateFood(int id, [FromBody] JsonPatchDocument<Fo
136136

137137
[HttpDelete]
138138
[Route("{id:int}", Name = nameof(RemoveFood))]
139-
public IActionResult RemoveFood(int id)
139+
public ActionResult<NoContentResult> RemoveFood(int id)
140140
{
141141
FoodItem foodItem = _foodRepository.GetSingle(id);
142142

@@ -157,7 +157,7 @@ public IActionResult RemoveFood(int id)
157157

158158
[HttpPut]
159159
[Route("{id:int}", Name = nameof(UpdateFood))]
160-
public IActionResult UpdateFood(int id, [FromBody]FoodUpdateDto foodUpdateDto)
160+
public ActionResult<OkObjectResult> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpdateDto)
161161
{
162162
if (foodUpdateDto == null)
163163
{
@@ -189,7 +189,7 @@ public IActionResult UpdateFood(int id, [FromBody]FoodUpdateDto foodUpdateDto)
189189
}
190190

191191
[HttpGet("GetRandomMeal", Name = nameof(GetRandomMeal))]
192-
public IActionResult GetRandomMeal()
192+
public ActionResult<object> GetRandomMeal()
193193
{
194194
ICollection<FoodItem> foodItems = _foodRepository.GetRandomMeal();
195195

@@ -296,15 +296,4 @@ private IEnumerable<LinkDto> GetLinks(int id)
296296
return links;
297297
}
298298
}
299-
300-
[ApiVersion("2.0")]
301-
[Route("api/v{version:apiVersion}/foods")]
302-
public class Foods2Controller : ControllerBase
303-
{
304-
[HttpGet]
305-
public IActionResult Get()
306-
{
307-
return Ok("2.0");
308-
}
309-
}
310299
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace SampleWebApiAspNetCore.v2.Controllers
4+
{
5+
[ApiVersion("2.0")]
6+
[Route("api/v{version:apiVersion}/foods")]
7+
public class FoodsController : ControllerBase
8+
{
9+
[HttpGet]
10+
public ActionResult<OkObjectResult> Get()
11+
{
12+
return Ok("2.0");
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)