diff --git a/RestApi.Test/V1/ExampleTest.cs b/RestApi.Test/V1/ExampleTest.cs index 3f3036c..ea846fd 100644 --- a/RestApi.Test/V1/ExampleTest.cs +++ b/RestApi.Test/V1/ExampleTest.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net; using System.Text.Json; using System.Threading.Tasks; using NUnit.Framework; -using RestApi.Models.V1; +using RestApi.Api.V1.Models; using RestApi.Test.Models; namespace RestApi.Test.V1 diff --git a/RestApi.Test/V2/ExampleTest.cs b/RestApi.Test/V2/ExampleTest.cs index e97b97e..1c3ba05 100644 --- a/RestApi.Test/V2/ExampleTest.cs +++ b/RestApi.Test/V2/ExampleTest.cs @@ -4,7 +4,7 @@ using System.Text.Json; using System.Threading.Tasks; using NUnit.Framework; -using RestApi.Models.V2; +using RestApi.Api.V2.Models; using RestApi.Test.Models; namespace RestApi.Test.V2 diff --git a/RestApi/Controllers/ErrorController.cs b/RestApi/Api/Common/Controllers/ErrorController.cs similarity index 96% rename from RestApi/Controllers/ErrorController.cs rename to RestApi/Api/Common/Controllers/ErrorController.cs index 695a323..e5436c1 100644 --- a/RestApi/Controllers/ErrorController.cs +++ b/RestApi/Api/Common/Controllers/ErrorController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; using NSwag.Annotations; -namespace RestApi.Controllers +namespace RestApi.Api.Common.Controllers { [ApiController] [ApiVersion("1")] diff --git a/RestApi/Controllers/V1/ExampleController.cs b/RestApi/Api/V1/Controllers/ExampleController.cs similarity index 81% rename from RestApi/Controllers/V1/ExampleController.cs rename to RestApi/Api/V1/Controllers/ExampleController.cs index 945b490..5804a78 100644 --- a/RestApi/Controllers/V1/ExampleController.cs +++ b/RestApi/Api/V1/Controllers/ExampleController.cs @@ -4,13 +4,17 @@ using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using RestApi.Models.V1; +using NSwag.Annotations; +using RestApi.Api.V1.Models; -namespace RestApi.Controllers.V1 +namespace RestApi.Api.V1.Controllers { + // Version is determined by Namespace Convention, which is set up in Startup.cs + // See more details about the convention in https://github.com/microsoft/aspnet-api-versioning/wiki/API-Version-Conventions + [ApiController] - [ApiVersion("1")] [Route("api/v{version:apiVersion}/[controller]")] + [OpenApiTag("API Example: Weather Forecast")] public partial class ExampleController : ControllerBase { private static readonly string[] Summaries = new[] diff --git a/RestApi/Models/V1/WeatherForecast.cs b/RestApi/Api/V1/Models/WeatherForecast.cs similarity index 90% rename from RestApi/Models/V1/WeatherForecast.cs rename to RestApi/Api/V1/Models/WeatherForecast.cs index 37f1acc..3f2dbc9 100644 --- a/RestApi/Models/V1/WeatherForecast.cs +++ b/RestApi/Api/V1/Models/WeatherForecast.cs @@ -1,7 +1,7 @@ using System; using System.Text.Json.Serialization; -namespace RestApi.Models.V1 +namespace RestApi.Api.V1.Models { public class WeatherForecast { diff --git a/RestApi/Controllers/V2/ExampleController.cs b/RestApi/Api/V2/Controllers/ExampleController.cs similarity index 87% rename from RestApi/Controllers/V2/ExampleController.cs rename to RestApi/Api/V2/Controllers/ExampleController.cs index 86da566..d974411 100644 --- a/RestApi/Controllers/V2/ExampleController.cs +++ b/RestApi/Api/V2/Controllers/ExampleController.cs @@ -4,13 +4,17 @@ using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using RestApi.Models.V2; +using NSwag.Annotations; +using RestApi.Api.V2.Models; -namespace RestApi.Controllers.V2 +namespace RestApi.Api.V2.Controllers { + // Version is determined by Namespace Convention, which is set up in Startup.cs + // See more details about the convention in https://github.com/microsoft/aspnet-api-versioning/wiki/API-Version-Conventions + [ApiController] - [ApiVersion("2")] [Route("api/v{version:apiVersion}/[controller]")] + [OpenApiTag("API Example: Weather Forecast")] public partial class ExampleController : ControllerBase { private static readonly string[] Areas = new[] diff --git a/RestApi/Models/V2/WeatherForecast.cs b/RestApi/Api/V2/Models/WeatherForecast.cs similarity index 91% rename from RestApi/Models/V2/WeatherForecast.cs rename to RestApi/Api/V2/Models/WeatherForecast.cs index 7ba527f..8c120e4 100644 --- a/RestApi/Models/V2/WeatherForecast.cs +++ b/RestApi/Api/V2/Models/WeatherForecast.cs @@ -1,7 +1,7 @@ using System; using System.Text.Json.Serialization; -namespace RestApi.Models.V2 +namespace RestApi.Api.V2.Models { public class WeatherForecast { diff --git a/RestApi/Startup.cs b/RestApi/Startup.cs index e8003c6..e2c2d2b 100644 --- a/RestApi/Startup.cs +++ b/RestApi/Startup.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Versioning.Conventions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -21,6 +22,7 @@ public void ConfigureServices(IServiceCollection services) services.AddApiVersioning(options => { + options.Conventions.Add(new VersionByNamespaceConvention()); options.ReportApiVersions = true; });