Skip to content

Commit 088f283

Browse files
committed
feat(#171): allow custom query parameters
1 parent fa66e5d commit 088f283

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ public class JsonApiOptions
1515
public bool AllowClientGeneratedIds { get; set; }
1616
public IContextGraph ContextGraph { get; set; }
1717
public bool RelativeLinks { get; set; }
18+
19+
/// <summary>
20+
/// This flag is experimental and could be perceived as a violation
21+
/// of the v1 spec. However, we have decided that this is a real
22+
/// requirement for users of this library and a gap in the specification.
23+
/// It will likely be removed when the spec is updated to support this
24+
/// requirement.
25+
/// </summary>
26+
public bool AllowCustomQueryParameters { get; set; }
1827
public IContractResolver JsonContractResolver { get; set; } = new DasherizedResolver();
1928
internal IContextGraphBuilder ContextGraphBuilder { get; } = new ContextGraphBuilder();
2029

src/JsonApiDotNetCore/Internal/Query/QuerySet.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ private void BuildQuerySet(IQueryCollection query)
6868
continue;
6969
}
7070

71-
throw new JsonApiException(400, $"{pair} is not a valid query.");
71+
if (_jsonApiContext.Options.AllowCustomQueryParameters == false)
72+
throw new JsonApiException(400, $"{pair} is not a valid query.");
7273
}
7374
}
7475

@@ -101,9 +102,9 @@ private List<FilterQuery> ParseFilterQuery(string key, string value)
101102
return (string.Empty, value);
102103

103104
// remove prefix from value
104-
if(Enum.TryParse(operation[0], out FilterOperations op) == false)
105+
if (Enum.TryParse(operation[0], out FilterOperations op) == false)
105106
return (string.Empty, value);
106-
107+
107108
var prefix = operation[0];
108109
value = string.Join(":", operation.Skip(1));
109110

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<VersionPrefix>2.1.5</VersionPrefix>
3+
<VersionPrefix>2.1.6</VersionPrefix>
44
<TargetFrameworks>netstandard1.6</TargetFrameworks>
55
<AssemblyName>JsonApiDotNetCore</AssemblyName>
66
<PackageId>JsonApiDotNetCore</PackageId>

0 commit comments

Comments
 (0)