Skip to content

Commit 33e3183

Browse files
author
Bart Koelman
committed
Clarified error message on type mismatch in request body
1 parent ad8c4c8 commit 33e3183

20 files changed

+21
-21
lines changed

src/JsonApiDotNetCore/Serialization/Request/Adapters/ResourceIdentityAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ private static void AssertIsCompatibleResourceType(ResourceType actual, Resource
7272
if (expected != null && !expected.ClrType.IsAssignableFrom(actual.ClrType))
7373
{
7474
string message = relationshipName != null
75-
? $"Type '{actual.PublicName}' is incompatible with type '{expected.PublicName}' of relationship '{relationshipName}'."
76-
: $"Type '{actual.PublicName}' is incompatible with type '{expected.PublicName}'.";
75+
? $"Type '{actual.PublicName}' is not convertible to type '{expected.PublicName}' of relationship '{relationshipName}'."
76+
: $"Type '{actual.PublicName}' is not convertible to type '{expected.PublicName}'.";
7777

7878
throw new ModelConversionException(state.Position, "Incompatible resource type found.", message, HttpStatusCode.Conflict);
7979
}

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public async Task Cannot_create_on_relationship_type_mismatch()
464464
ErrorObject error = responseDocument.Errors[0];
465465
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
466466
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
467-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
467+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers' of relationship 'performers'.");
468468
error.Source.ShouldNotBeNull();
469469
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]/type");
470470
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public async Task Cannot_create_on_relationship_type_mismatch()
648648
ErrorObject error = responseDocument.Errors[0];
649649
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
650650
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
651-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'lyrics' of relationship 'lyric'.");
651+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'lyrics' of relationship 'lyric'.");
652652
error.Source.ShouldNotBeNull();
653653
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data/type");
654654
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicAddToToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
10261026
ErrorObject error = responseDocument.Errors[0];
10271027
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
10281028
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1029-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
1029+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers' of relationship 'performers'.");
10301030
error.Source.ShouldNotBeNull();
10311031
error.Source.Pointer.Should().Be("/atomic:operations[0]/data[0]/type");
10321032
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicRemoveFromToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
986986
ErrorObject error = responseDocument.Errors[0];
987987
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
988988
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
989-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
989+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers' of relationship 'performers'.");
990990
error.Source.ShouldNotBeNull();
991991
error.Source.Pointer.Should().Be("/atomic:operations[0]/data[0]/type");
992992
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicReplaceToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
11351135
ErrorObject error = responseDocument.Errors[0];
11361136
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
11371137
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1138-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
1138+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers' of relationship 'performers'.");
11391139
error.Source.ShouldNotBeNull();
11401140
error.Source.Pointer.Should().Be("/atomic:operations[0]/data[0]/type");
11411141
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicUpdateToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
13001300
ErrorObject error = responseDocument.Errors[0];
13011301
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
13021302
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1303-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'lyrics' of relationship 'lyric'.");
1303+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'lyrics' of relationship 'lyric'.");
13041304
error.Source.ShouldNotBeNull();
13051305
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/type");
13061306
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicReplaceToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
794794
ErrorObject error = responseDocument.Errors[0];
795795
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
796796
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
797-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
797+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers' of relationship 'performers'.");
798798
error.Source.ShouldNotBeNull();
799799
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]/type");
800800
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ public async Task Cannot_update_on_resource_type_mismatch_between_ref_and_data()
11491149
ErrorObject error = responseDocument.Errors[0];
11501150
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
11511151
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1152-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers'.");
1152+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'performers'.");
11531153
error.Source.ShouldNotBeNull();
11541154
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/type");
11551155
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
10411041
ErrorObject error = responseDocument.Errors[0];
10421042
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
10431043
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1044-
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'lyrics' of relationship 'lyric'.");
1044+
error.Detail.Should().Be("Type 'playlists' is not convertible to type 'lyrics' of relationship 'lyric'.");
10451045
error.Source.ShouldNotBeNull();
10461046
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data/type");
10471047
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public async Task Cannot_create_on_resource_type_mismatch_between_url_and_body()
722722
ErrorObject error = responseDocument.Errors[0];
723723
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
724724
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
725-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'workItems'.");
725+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'workItems'.");
726726
error.Source.ShouldNotBeNull();
727727
error.Source.Pointer.Should().Be("/data/type");
728728
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public async Task Cannot_create_on_relationship_type_mismatch()
556556
ErrorObject error = responseDocument.Errors[0];
557557
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
558558
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
559-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'userAccounts' of relationship 'subscribers'.");
559+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'userAccounts' of relationship 'subscribers'.");
560560
error.Source.ShouldNotBeNull();
561561
error.Source.Pointer.Should().Be("/data/relationships/subscribers/data[0]/type");
562562
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ public async Task Cannot_create_on_relationship_type_mismatch()
641641
ErrorObject error = responseDocument.Errors[0];
642642
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
643643
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
644-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'userAccounts' of relationship 'assignee'.");
644+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'userAccounts' of relationship 'assignee'.");
645645
error.Source.ShouldNotBeNull();
646646
error.Source.Pointer.Should().Be("/data/relationships/assignee/data/type");
647647
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/AddToToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
634634
ErrorObject error = responseDocument.Errors[0];
635635
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
636636
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
637-
error.Detail.Should().Be("Type 'userAccounts' is incompatible with type 'workTags' of relationship 'tags'.");
637+
error.Detail.Should().Be("Type 'userAccounts' is not convertible to type 'workTags' of relationship 'tags'.");
638638
error.Source.ShouldNotBeNull();
639639
error.Source.Pointer.Should().Be("/data[0]/type");
640640
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/RemoveFromToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
750750
ErrorObject error = responseDocument.Errors[0];
751751
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
752752
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
753-
error.Detail.Should().Be("Type 'userAccounts' is incompatible with type 'workTags' of relationship 'tags'.");
753+
error.Detail.Should().Be("Type 'userAccounts' is not convertible to type 'workTags' of relationship 'tags'.");
754754
error.Source.ShouldNotBeNull();
755755
error.Source.Pointer.Should().Be("/data[0]/type");
756756
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/ReplaceToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
661661
ErrorObject error = responseDocument.Errors[0];
662662
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
663663
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
664-
error.Detail.Should().Be("Type 'userAccounts' is incompatible with type 'workTags' of relationship 'tags'.");
664+
error.Detail.Should().Be("Type 'userAccounts' is not convertible to type 'workTags' of relationship 'tags'.");
665665
error.Source.ShouldNotBeNull();
666666
error.Source.Pointer.Should().Be("/data[0]/type");
667667
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/UpdateToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
689689
ErrorObject error = responseDocument.Errors[0];
690690
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
691691
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
692-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'userAccounts' of relationship 'assignee'.");
692+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'userAccounts' of relationship 'assignee'.");
693693
error.Source.ShouldNotBeNull();
694694
error.Source.Pointer.Should().Be("/data/type");
695695
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
697697
ErrorObject error = responseDocument.Errors[0];
698698
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
699699
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
700-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'userAccounts' of relationship 'subscribers'.");
700+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'userAccounts' of relationship 'subscribers'.");
701701
error.Source.ShouldNotBeNull();
702702
error.Source.Pointer.Should().Be("/data/relationships/subscribers/data[0]/type");
703703
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
10391039
ErrorObject error = responseDocument.Errors[0];
10401040
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
10411041
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
1042-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'workItems'.");
1042+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'workItems'.");
10431043
error.Source.ShouldNotBeNull();
10441044
error.Source.Pointer.Should().Be("/data/type");
10451045
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
836836
ErrorObject error = responseDocument.Errors[0];
837837
error.StatusCode.Should().Be(HttpStatusCode.Conflict);
838838
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
839-
error.Detail.Should().Be("Type 'rgbColors' is incompatible with type 'userAccounts' of relationship 'assignee'.");
839+
error.Detail.Should().Be("Type 'rgbColors' is not convertible to type 'userAccounts' of relationship 'assignee'.");
840840
error.Source.ShouldNotBeNull();
841841
error.Source.Pointer.Should().Be("/data/relationships/assignee/data/type");
842842
error.Meta.ShouldContainKey("requestBody").With(value => value.ShouldNotBeNull().ToString().ShouldNotBeEmpty());

0 commit comments

Comments
 (0)