diff --git a/JsonApiDotNetCore/Configuration/JsonApiConfigurationBuilder.cs b/JsonApiDotNetCore/Configuration/JsonApiConfigurationBuilder.cs index 4debb4d227..9973520c9d 100644 --- a/JsonApiDotNetCore/Configuration/JsonApiConfigurationBuilder.cs +++ b/JsonApiDotNetCore/Configuration/JsonApiConfigurationBuilder.cs @@ -3,9 +3,7 @@ using JsonApiDotNetCore.Routing; using Microsoft.EntityFrameworkCore; using System.Linq; -using System.Linq.Expressions; using AutoMapper; -using JsonApiDotNetCore.Abstractions; using JsonApiDotNetCore.Attributes; namespace JsonApiDotNetCore.Configuration diff --git a/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs b/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs index bb69a2304b..85e2c9fcbe 100644 --- a/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs +++ b/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs @@ -36,6 +36,8 @@ public async Task Invoke(HttpContext context) } else { + _logger.LogWarning("Request not handled by JsonApiDotNetCore"); + await _next.Invoke(context); RespondUnsupportedMediaType(context); @@ -51,14 +53,13 @@ private bool IsJsonApiRequest(HttpContext context) if(context.Request.ContentType == "application/vnd.api+json") { return true; } - _logger.LogInformation("Content-Type invalid for JsonAPI"); + _logger.LogWarning("Content-Type invalid for JsonAPI, must be application/vnd.api+json"); return false; } return true; } - _logger.LogInformation("Accept header invalid for JsonAPI"); - + _logger.LogWarning("Accept header invalid for JsonAPI, must be application/vnd.api+json"); return false; } diff --git a/JsonApiDotNetCore/Routing/RouteBuilder.cs b/JsonApiDotNetCore/Routing/RouteBuilder.cs index 167d5b9abc..56ad73f916 100644 --- a/JsonApiDotNetCore/Routing/RouteBuilder.cs +++ b/JsonApiDotNetCore/Routing/RouteBuilder.cs @@ -83,7 +83,7 @@ private Type GetTypeOfRelatedResource(string relationshipName) // TODO: Why is this here? public static string BuildRoute(string nameSpace, string resourceCollectionName) { - return $"/{nameSpace}/{resourceCollectionName}"; + return $"/{nameSpace}/{resourceCollectionName.Dasherize()}"; } } } diff --git a/JsonApiDotNetCoreTests/Routing/UnitTests/RouteBuilderTests.cs b/JsonApiDotNetCoreTests/Routing/UnitTests/RouteBuilderTests.cs new file mode 100644 index 0000000000..8ce40c176a --- /dev/null +++ b/JsonApiDotNetCoreTests/Routing/UnitTests/RouteBuilderTests.cs @@ -0,0 +1,23 @@ +using Xunit; +using JsonApiDotNetCore.Routing; + +namespace JsonApiDotNetCoreTests.Routing.UnitTests +{ + public class RoutBuilderTests + { + [Theory] + [InlineData("api/v1","People","/api/v1/people")] + [InlineData("api/v1","TodoItems","/api/v1/todo-items")] + [InlineData("api","todoItems","/api/todo-items")] + [InlineData("api","MoreModelsHere","/api/more-models-here")] + public void BuildRoute_Returns_CorrectRoute(string nameSpace, string collectionName, string expectOutput) + { + // arrange + // act + var result = RouteBuilder.BuildRoute(nameSpace, collectionName); + + // assert + Assert.Equal(expectOutput, result); + } + } +} diff --git a/README.md b/README.md index 2d945db2f5..5d6ee1f01c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ public class PersonResource : IJsonApiResource ``` We use [AutoMapper](http://automapper.org/) to map from the model class to the resource class. -The below snippet shows how you can specify a custom mapping expression in your `Startup` class that will append `_1` to the resource name. +The below snippet is a trivial example of how you can specify a custom mapping expression in your `Startup` class. +In this example, the first and last name are concatenated and used for the value of the resource's DisplayName property. Check out [AutoMapper's Wiki](https://github.com/AutoMapper/AutoMapper/wiki) for detailed mapping options. ``` @@ -76,7 +77,7 @@ services.AddJsonApi(config => { config.AddResourceMapping(map => { // resource.Name = model.Name + "_1" - map.ForMember("Name", opt => opt.MapFrom(src => $"{((Person)src).Name}_1")); + map.ForMember("DisplayName", opt => opt.MapFrom(src => $"{((Person)src).FirstName} {((Person)src).LastName}")); }); ... }); @@ -94,9 +95,11 @@ services.AddJsonApi(config => { }); ``` -The controller **MUST** implement `IJsonApiController`, and it **MAY** inherit from [JsonApiController](https://github.com/Research-Institute/json-api-dotnet-core/blob/master/JsonApiDotNetCore/Controllers/JsonApiController.cs). +- The controller **MUST** implement `IJsonApiController` +- Controllers **MAY** inherit from [JsonApiController](https://github.com/Research-Institute/json-api-dotnet-core/blob/master/JsonApiDotNetCore/Controllers/JsonApiController.cs). + Constructor dependency injection will work like normal. -Any services added in your `Startup.ConfigureServices()` method will be injected into the constructor parameters. +Any services in your `Startup.ConfigureServices()` method will be injected into the constructor parameters. ``` public class TodoItemsController : JsonApiController, IJsonApiController