Skip to content

Commit 9c74c33

Browse files
committed
Correct relationship data requiredness in response models, so the generator doesn't need to overrule it
1 parent 946c472 commit 9c74c33

File tree

4 files changed

+3
-8
lines changed

4 files changed

+3
-8
lines changed

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiObjects/Relationships/NullableToOneRelationshipInResponse.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32
using JetBrains.Annotations;
43
using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.Links;
@@ -15,7 +14,7 @@ internal sealed class NullableToOneRelationshipInResponse<TResource>
1514
[JsonPropertyName("links")]
1615
public RelationshipLinks Links { get; set; } = null!;
1716

18-
[Required]
17+
// Non-required because related data may not be included in the response.
1918
[JsonPropertyName("data")]
2019
public ResourceIdentifierInResponse<TResource>? Data { get; set; }
2120

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiObjects/Relationships/ToManyRelationshipInResponse.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32
using JetBrains.Annotations;
43
using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.Links;
@@ -15,7 +14,7 @@ internal sealed class ToManyRelationshipInResponse<TResource>
1514
[JsonPropertyName("links")]
1615
public RelationshipLinks Links { get; set; } = null!;
1716

18-
[Required]
17+
// Non-required because related data may not be included in the response.
1918
[JsonPropertyName("data")]
2019
public ICollection<ResourceIdentifierInResponse<TResource>> Data { get; set; } = null!;
2120

src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiObjects/Relationships/ToOneRelationshipInResponse.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32
using JetBrains.Annotations;
43
using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.Links;
@@ -15,7 +14,7 @@ internal sealed class ToOneRelationshipInResponse<TResource>
1514
[JsonPropertyName("links")]
1615
public RelationshipLinks Links { get; set; } = null!;
1716

18-
[Required]
17+
// Non-required because related data may not be included in the response.
1918
[JsonPropertyName("data")]
2019
public ResourceIdentifierInResponse<TResource> Data { get; set; } = null!;
2120

src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/ResourceFieldSchemaBuilder.cs

-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ private OpenApiSchema CreateReferenceSchemaForRelationship(Type relationshipSche
207207
if (JsonApiSchemaFacts.IsRelationshipInResponseType(relationshipSchemaType))
208208
{
209209
_linksVisibilitySchemaGenerator.UpdateSchemaForRelationship(relationshipSchemaType, fullSchema, schemaRepository);
210-
211-
fullSchema.Required.Remove(JsonApiPropertyName.Data);
212210
}
213211

214212
return referenceSchema;

0 commit comments

Comments
 (0)