From 111773f8905b3d02fc393bc073c660dc172825b8 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Mon, 5 Jun 2017 21:20:51 -0500 Subject: [PATCH 1/3] update documentation --- README.md | 6 ++---- docs/Controllers.md | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b5f3a9cd55..43b78cc023 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![MyGet CI](https://img.shields.io/myget/research-institute/vpre/JsonApiDotNetCore.svg)](https://www.myget.org/feed/research-institute/package/nuget/JsonApiDotNetCore) [![Join the chat at https://gitter.im/json-api-dotnet-core/Lobby](https://badges.gitter.im/json-api-dotnet-core/Lobby.svg)](https://gitter.im/json-api-dotnet-core/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -A framework for building [json:api](http://jsonapi.org/) compliant web servers. It allows you to eliminate a significant amount of boilerplate while offering out-of-the-box features such as sorting, filtering and pagination. This library provides all the required middleware to build a complete server. All you need to focus on is defining the resources and implementing your custom business logic. This library has been designed around dependency injection making extensibility incredibly easy. +A framework for building [json:api](http://jsonapi.org/) compliant web APIs. The ultimate goal of this library is to eliminate as much boilerplate as possible by offering out-of-the-box features such as sorting, filtering and pagination. You just need to focus on defining the resources and implementing your custom business logic. This library has been designed around dependency injection making extensibility incredibly easy. ## Installation And Usage @@ -18,7 +18,5 @@ See the documentation [here](https://research-institute.github.io/json-api-dotne Branch `feat/core-2` is where I am working on .Net Core 2 compatibility tests and package upgrades. There are several blockers to be aware of: -- Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard. -This will be fixed in future versions. -- EF bug against netcoreapp2.0 runtime ([EntityFramework#8021](https://github.com/aspnet/EntityFramework/issues/8021)) +- Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard. [This will be changed in future versions.](https://blogs.msdn.microsoft.com/webdev/2017/05/10/aspnet-2-preview-1/). - Can't run acceptance testing against postgres on preview runtime [pgsql.EntityFrameworkCore.PostgreSQL#171](https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/171#issuecomment-301287257) diff --git a/docs/Controllers.md b/docs/Controllers.md index 2d365becd3..0ec47b8774 100644 --- a/docs/Controllers.md +++ b/docs/Controllers.md @@ -38,9 +38,31 @@ public class ThingsController : JsonApiController } ``` -### Controller-level customizations +### Limiting Write Access -If you need to customize things at the controller level, you can override the virtual +It is possible to limit write resource access on the controller entirely using the following attributes: + +- `NoHttpPost`: disallow POST requests +- `NoHttpPatch`: disallow PATCH requests +- `NoHttpDelete`: disallow DELETE requests +- `HttpReadOnly`: all of the above + +```csharp +[HttpReadOnly] +public class ThingsController : JsonApiController +{ + public ThingsController( + IJsonApiContext jsonApiContext, + IResourceService resourceService, + ILoggerFactory loggerFactory) + : base(jsonApiContext, resourceService, loggerFactory) + { } +} +``` + +### Additional customizations + +If you need additional customization at the controller level, you can override the virtual methods. Please be aware that this is not the place for advanced business logic which should be performed at the [service](resourceservices.html) or [repository](entityrepositories.html) layers. Here is an example override at the controller layer: From 1632509dc99cb74d3bdafaed766f0bc35b5b0592 Mon Sep 17 00:00:00 2001 From: Jason Petrik Date: Wed, 14 Jun 2017 08:18:38 -0700 Subject: [PATCH 2/3] fix(deserialization): deserialize enums fix exception thrown when attributes are of an enum type during deserialization --- src/JsonApiDotNetCore/Internal/TypeHelper.cs | 3 +++ test/UnitTests/Internal/TypeHelper_Tests.cs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/JsonApiDotNetCore/Internal/TypeHelper.cs b/src/JsonApiDotNetCore/Internal/TypeHelper.cs index 60574ff295..ca382c10d6 100644 --- a/src/JsonApiDotNetCore/Internal/TypeHelper.cs +++ b/src/JsonApiDotNetCore/Internal/TypeHelper.cs @@ -22,6 +22,9 @@ public static object ConvertType(object value, Type type) if (type == typeof(DateTimeOffset)) return DateTimeOffset.Parse(stringValue); + if (type.GetTypeInfo().IsEnum) + return Enum.Parse(type, stringValue); + return Convert.ChangeType(stringValue, type); } catch (Exception e) diff --git a/test/UnitTests/Internal/TypeHelper_Tests.cs b/test/UnitTests/Internal/TypeHelper_Tests.cs index 7f05edd892..1e75e705d2 100644 --- a/test/UnitTests/Internal/TypeHelper_Tests.cs +++ b/test/UnitTests/Internal/TypeHelper_Tests.cs @@ -30,5 +30,23 @@ public void Bad_DateTimeOffset_String_Throws() // assert Assert.Throws(() => TypeHelper.ConvertType(formattedString, typeof(DateTimeOffset))); } + + [Fact] + public void Can_Convert_Enums() + { + // arrange + var formattedString = "1"; + + // act + var result = TypeHelper.ConvertType(formattedString, typeof(TestEnum)); + + // assert + Assert.Equal(TestEnum.Test, result); + } + + public enum TestEnum + { + Test = 1 + } } } From d45fe14df9b0d7b48e3417f724fe13e57189bc9c Mon Sep 17 00:00:00 2001 From: Jason Petrik Date: Wed, 14 Jun 2017 08:50:09 -0700 Subject: [PATCH 3/3] version bump to 2.0.9 --- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index 699a20076b..01b1879e83 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.0.8 + 2.0.9 netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore @@ -21,4 +21,4 @@ - \ No newline at end of file +