Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c4c27aa
disable validator if partial patch
sasman0001 Jun 9, 2020
ead6930
Create required validator that can be diabled to allow for partial pa…
sasman0001 Jun 9, 2020
a4c688d
formatting
sasman0001 Jun 9, 2020
7d3f57a
Remove unneeded reference.
sasman0001 Jun 9, 2020
11bd7d9
package reference
sasman0001 Jun 9, 2020
c02ef34
Requested changes:
sasman0001 Jun 10, 2020
9e40b88
Add version wildcard
sasman0001 Jun 10, 2020
a0de349
expect possible null in HttpContextExtension method
sasman0001 Jun 10, 2020
86989e6
change parameter order and naming for consistency
sasman0001 Jun 10, 2020
50ae2e4
Requested changes
sasman0001 Jun 10, 2020
102e636
Remove unneeded null check.
sasman0001 Jun 10, 2020
3917539
add null checks
sasman0001 Jun 10, 2020
cfbc9e3
generate fake name for author
sasman0001 Jun 10, 2020
0bcebe3
Moved logic to RequestDeserializer, overriding methods in BaseDocumen…
sasman0001 Jun 10, 2020
6a682ed
remove references
sasman0001 Jun 10, 2020
c2f2a69
formatting
sasman0001 Jun 10, 2020
81e764e
back to var
sasman0001 Jun 10, 2020
126a1a8
Requested changes:
sasman0001 Jun 11, 2020
a1596d5
formatting
sasman0001 Jun 11, 2020
d82f193
formatting
sasman0001 Jun 11, 2020
6882b19
change access modifiers
sasman0001 Jun 11, 2020
96cbd84
Requested changes:
sasman0001 Jun 15, 2020
945691d
refactor
sasman0001 Jun 15, 2020
4496d72
remoev comma.
sasman0001 Jun 15, 2020
4bc23b7
Merge remote-tracking branch 'upstream/master' into input_validation_…
sasman0001 Jun 16, 2020
7eeb6c5
Cleanup
Jun 16, 2020
44a9d92
removed unneeded code
Jun 16, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
expect possible null in HttpContextExtension method
  • Loading branch information
sasman0001 committed Jun 10, 2020
commit a0de349fe4476f3066e8052af4e8761885bd7c8e
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ internal static void SetJsonApiRequest(this HttpContext httpContext)
httpContext.Items["IsJsonApiRequest"] = bool.TrueString;
}

internal static void DisableValidator(this HttpContext httpContext, string model, string name)
internal static void DisableValidator(this HttpContext httpContext, string propertyName, string model = null)
{
if (httpContext == null) return;
var itemKey = $"JsonApiDotNetCore_DisableValidation_{model}_{name}";
if (!httpContext.Items.ContainsKey(itemKey))
var itemKey = $"JsonApiDotNetCore_DisableValidation_{model}_{propertyName}";
if (!httpContext.Items.ContainsKey(itemKey) && model != null)
{
httpContext.Items.Add(itemKey, true);
}
Expand Down
22 changes: 11 additions & 11 deletions src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ protected IIdentifiable SetAttributes(IIdentifiable entity, Dictionary<string, o
{
foreach (var attr in attributes)
{
var disableValidator = false;
if (attributeValues == null || attributeValues.Count == 0)
{
if (_httpContextAccessor?.HttpContext?.Request.Method != "PATCH") continue;
if (attr.PropertyInfo.GetCustomAttribute<IsRequiredAttribute>() != null)
{
_httpContextAccessor.HttpContext.DisableValidator(attr.PropertyInfo.ReflectedType?.Name, attr.PropertyInfo.Name);
}
disableValidator = true;
}
else
{
Expand All @@ -96,13 +93,16 @@ protected IIdentifiable SetAttributes(IIdentifiable entity, Dictionary<string, o
}
else
{
if (_httpContextAccessor?.HttpContext?.Request.Method != "PATCH") continue;
if (attr.PropertyInfo.GetCustomAttribute<IsRequiredAttribute>() != null)
{
_httpContextAccessor.HttpContext.DisableValidator(attr.PropertyInfo.ReflectedType?.Name, attr.PropertyInfo.Name);
}
disableValidator = true;
}
}

if (!disableValidator) continue;
if (_httpContextAccessor?.HttpContext?.Request.Method != "PATCH") continue;
if (attr.PropertyInfo.GetCustomAttribute<IsRequiredAttribute>() != null)
{
_httpContextAccessor.HttpContext.DisableValidator(attr.PropertyInfo.Name, attr.PropertyInfo.ReflectedType?.Name);
}
}

return entity;
Expand All @@ -123,7 +123,7 @@ protected IIdentifiable SetRelationships(IIdentifiable entity, Dictionary<string
var entityProperties = entity.GetType().GetProperties();
foreach (var attr in relationshipAttributes)
{
_httpContextAccessor?.HttpContext?.DisableValidator(attr.PropertyInfo.Name, "Relation");
_httpContextAccessor?.HttpContext?.DisableValidator( "Relation", attr.PropertyInfo.Name);

if (!relationshipsValues.TryGetValue(attr.PublicRelationshipName, out RelationshipEntry relationshipData) || !relationshipData.IsPopulated)
continue;
Expand Down