From 148cc33cef47d0e708dec70da3b14395f4e8e7b9 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Tue, 3 Oct 2017 21:45:20 -0500 Subject: [PATCH 1/2] feat(#171): allow custom query parameters --- src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs | 9 +++++++++ src/JsonApiDotNetCore/Internal/Query/QuerySet.cs | 7 ++++--- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs index 2e24d52d53..3d169998a3 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs @@ -15,6 +15,15 @@ public class JsonApiOptions public bool AllowClientGeneratedIds { get; set; } public IContextGraph ContextGraph { get; set; } public bool RelativeLinks { get; set; } + + /// + /// This flag is experimental and could be perceived as a violation + /// of the v1 spec. However, we have decided that this is a real + /// requirement for users of this library and a gap in the specification. + /// It will likely be removed when the spec is updated to support this + /// requirement. + /// + public bool AllowCustomQueryParameters { get; set; } public IContractResolver JsonContractResolver { get; set; } = new DasherizedResolver(); internal IContextGraphBuilder ContextGraphBuilder { get; } = new ContextGraphBuilder(); diff --git a/src/JsonApiDotNetCore/Internal/Query/QuerySet.cs b/src/JsonApiDotNetCore/Internal/Query/QuerySet.cs index acf448d69d..628e6187a3 100644 --- a/src/JsonApiDotNetCore/Internal/Query/QuerySet.cs +++ b/src/JsonApiDotNetCore/Internal/Query/QuerySet.cs @@ -68,7 +68,8 @@ private void BuildQuerySet(IQueryCollection query) continue; } - throw new JsonApiException(400, $"{pair} is not a valid query."); + if (_jsonApiContext.Options.AllowCustomQueryParameters == false) + throw new JsonApiException(400, $"{pair} is not a valid query."); } } @@ -101,9 +102,9 @@ private List ParseFilterQuery(string key, string value) return (string.Empty, value); // remove prefix from value - if(Enum.TryParse(operation[0], out FilterOperations op) == false) + if (Enum.TryParse(operation[0], out FilterOperations op) == false) return (string.Empty, value); - + var prefix = operation[0]; value = string.Join(":", operation.Skip(1)); diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index baad778f59..9177566e00 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.1.5 + 2.1.6 netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore From 5b2ae04a2e79f99a3e6ff7696104b1f8c5fbbde4 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Tue, 3 Oct 2017 21:45:40 -0500 Subject: [PATCH 2/2] fix(#172): get filter value should ignore case --- src/JsonApiDotNetCore/Services/QueryAccessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Services/QueryAccessor.cs b/src/JsonApiDotNetCore/Services/QueryAccessor.cs index 0862e3fd3e..09942d4031 100644 --- a/src/JsonApiDotNetCore/Services/QueryAccessor.cs +++ b/src/JsonApiDotNetCore/Services/QueryAccessor.cs @@ -63,7 +63,7 @@ public bool TryGetValue(string key, out T value) private string GetFilterValue(string key) => _jsonApiContext.QuerySet .Filters - .FirstOrDefault(f => f.Key == key) + .FirstOrDefault(f => string.Equals(f.Key, key, StringComparison.OrdinalIgnoreCase)) ?.Value; } } \ No newline at end of file