Skip to content

Commit b53ece1

Browse files
committed
Add missing properties to ErrorResponseDocument
1 parent 22b00b3 commit b53ece1

File tree

34 files changed

+965
-23
lines changed

34 files changed

+965
-23
lines changed

src/Examples/JsonApiDotNetCoreExample/GeneratedSwagger/JsonApiDotNetCoreExample.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4781,15 +4781,30 @@
47814781
},
47824782
"errorResponseDocument": {
47834783
"required": [
4784-
"errors"
4784+
"errors",
4785+
"links"
47854786
],
47864787
"type": "object",
47874788
"properties": {
4789+
"links": {
4790+
"allOf": [
4791+
{
4792+
"$ref": "#/components/schemas/linksInErrorDocument"
4793+
}
4794+
]
4795+
},
47884796
"errors": {
47894797
"type": "array",
47904798
"items": {
47914799
"$ref": "#/components/schemas/errorObject"
47924800
}
4801+
},
4802+
"meta": {
4803+
"type": "object",
4804+
"additionalProperties": {
4805+
"type": "object",
4806+
"nullable": true
4807+
}
47934808
}
47944809
},
47954810
"additionalProperties": false
@@ -4812,6 +4827,22 @@
48124827
},
48134828
"additionalProperties": false
48144829
},
4830+
"linksInErrorDocument": {
4831+
"required": [
4832+
"self"
4833+
],
4834+
"type": "object",
4835+
"properties": {
4836+
"self": {
4837+
"minLength": 1,
4838+
"type": "string"
4839+
},
4840+
"describedby": {
4841+
"type": "string"
4842+
}
4843+
},
4844+
"additionalProperties": false
4845+
},
48154846
"linksInRelationship": {
48164847
"required": [
48174848
"related",

src/Examples/OpenApiKiotaClientExample/GeneratedCode/Models/ErrorResponseDocument.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,37 @@ public List<ErrorObject> Errors {
2323
get { return BackingStore?.Get<List<ErrorObject>>("errors"); }
2424
set { BackingStore?.Set("errors", value); }
2525
}
26+
#endif
27+
/// <summary>The links property</summary>
28+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
29+
#nullable enable
30+
public LinksInErrorDocument? Links {
31+
get { return BackingStore?.Get<LinksInErrorDocument?>("links"); }
32+
set { BackingStore?.Set("links", value); }
33+
}
34+
#nullable restore
35+
#else
36+
public LinksInErrorDocument Links {
37+
get { return BackingStore?.Get<LinksInErrorDocument>("links"); }
38+
set { BackingStore?.Set("links", value); }
39+
}
2640
#endif
2741
/// <summary>The primary error message.</summary>
2842
public override string Message { get => base.Message; }
43+
/// <summary>The meta property</summary>
44+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
45+
#nullable enable
46+
public ErrorResponseDocument_meta? Meta {
47+
get { return BackingStore?.Get<ErrorResponseDocument_meta?>("meta"); }
48+
set { BackingStore?.Set("meta", value); }
49+
}
50+
#nullable restore
51+
#else
52+
public ErrorResponseDocument_meta Meta {
53+
get { return BackingStore?.Get<ErrorResponseDocument_meta>("meta"); }
54+
set { BackingStore?.Set("meta", value); }
55+
}
56+
#endif
2957
/// <summary>
3058
/// Instantiates a new errorResponseDocument and sets the default values.
3159
/// </summary>
@@ -46,6 +74,8 @@ public static ErrorResponseDocument CreateFromDiscriminatorValue(IParseNode pars
4674
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
4775
return new Dictionary<string, Action<IParseNode>> {
4876
{"errors", n => { Errors = n.GetCollectionOfObjectValues<ErrorObject>(ErrorObject.CreateFromDiscriminatorValue)?.ToList(); } },
77+
{"links", n => { Links = n.GetObjectValue<LinksInErrorDocument>(LinksInErrorDocument.CreateFromDiscriminatorValue); } },
78+
{"meta", n => { Meta = n.GetObjectValue<ErrorResponseDocument_meta>(ErrorResponseDocument_meta.CreateFromDiscriminatorValue); } },
4979
};
5080
}
5181
/// <summary>
@@ -55,6 +85,8 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
5585
public virtual void Serialize(ISerializationWriter writer) {
5686
_ = writer ?? throw new ArgumentNullException(nameof(writer));
5787
writer.WriteCollectionOfObjectValues<ErrorObject>("errors", Errors);
88+
writer.WriteObjectValue<LinksInErrorDocument>("links", Links);
89+
writer.WriteObjectValue<ErrorResponseDocument_meta>("meta", Meta);
5890
}
5991
}
6092
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// <auto-generated/>
2+
using Microsoft.Kiota.Abstractions.Serialization;
3+
using Microsoft.Kiota.Abstractions.Store;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System;
8+
namespace OpenApiKiotaClientExample.GeneratedCode.Models {
9+
public class ErrorResponseDocument_meta : IAdditionalDataHolder, IBackedModel, IParsable {
10+
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
11+
public IDictionary<string, object> AdditionalData {
12+
get { return BackingStore?.Get<IDictionary<string, object>>("AdditionalData"); }
13+
set { BackingStore?.Set("AdditionalData", value); }
14+
}
15+
/// <summary>Stores model information.</summary>
16+
public IBackingStore BackingStore { get; private set; }
17+
/// <summary>
18+
/// Instantiates a new errorResponseDocument_meta and sets the default values.
19+
/// </summary>
20+
public ErrorResponseDocument_meta() {
21+
BackingStore = BackingStoreFactorySingleton.Instance.CreateBackingStore();
22+
AdditionalData = new Dictionary<string, object>();
23+
}
24+
/// <summary>
25+
/// Creates a new instance of the appropriate class based on discriminator value
26+
/// </summary>
27+
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
28+
public static ErrorResponseDocument_meta CreateFromDiscriminatorValue(IParseNode parseNode) {
29+
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
30+
return new ErrorResponseDocument_meta();
31+
}
32+
/// <summary>
33+
/// The deserialization information for the current model
34+
/// </summary>
35+
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
36+
return new Dictionary<string, Action<IParseNode>> {
37+
};
38+
}
39+
/// <summary>
40+
/// Serializes information the current object
41+
/// </summary>
42+
/// <param name="writer">Serialization writer to use to serialize this model</param>
43+
public virtual void Serialize(ISerializationWriter writer) {
44+
_ = writer ?? throw new ArgumentNullException(nameof(writer));
45+
writer.WriteAdditionalData(AdditionalData);
46+
}
47+
}
48+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// <auto-generated/>
2+
using Microsoft.Kiota.Abstractions.Serialization;
3+
using Microsoft.Kiota.Abstractions.Store;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System;
8+
namespace OpenApiKiotaClientExample.GeneratedCode.Models {
9+
public class LinksInErrorDocument : IBackedModel, IParsable {
10+
/// <summary>Stores model information.</summary>
11+
public IBackingStore BackingStore { get; private set; }
12+
/// <summary>The describedby property</summary>
13+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
14+
#nullable enable
15+
public string? Describedby {
16+
get { return BackingStore?.Get<string?>("describedby"); }
17+
set { BackingStore?.Set("describedby", value); }
18+
}
19+
#nullable restore
20+
#else
21+
public string Describedby {
22+
get { return BackingStore?.Get<string>("describedby"); }
23+
set { BackingStore?.Set("describedby", value); }
24+
}
25+
#endif
26+
/// <summary>The self property</summary>
27+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
28+
#nullable enable
29+
public string? Self {
30+
get { return BackingStore?.Get<string?>("self"); }
31+
set { BackingStore?.Set("self", value); }
32+
}
33+
#nullable restore
34+
#else
35+
public string Self {
36+
get { return BackingStore?.Get<string>("self"); }
37+
set { BackingStore?.Set("self", value); }
38+
}
39+
#endif
40+
/// <summary>
41+
/// Instantiates a new linksInErrorDocument and sets the default values.
42+
/// </summary>
43+
public LinksInErrorDocument() {
44+
BackingStore = BackingStoreFactorySingleton.Instance.CreateBackingStore();
45+
}
46+
/// <summary>
47+
/// Creates a new instance of the appropriate class based on discriminator value
48+
/// </summary>
49+
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
50+
public static LinksInErrorDocument CreateFromDiscriminatorValue(IParseNode parseNode) {
51+
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
52+
return new LinksInErrorDocument();
53+
}
54+
/// <summary>
55+
/// The deserialization information for the current model
56+
/// </summary>
57+
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
58+
return new Dictionary<string, Action<IParseNode>> {
59+
{"describedby", n => { Describedby = n.GetStringValue(); } },
60+
{"self", n => { Self = n.GetStringValue(); } },
61+
};
62+
}
63+
/// <summary>
64+
/// Serializes information the current object
65+
/// </summary>
66+
/// <param name="writer">Serialization writer to use to serialize this model</param>
67+
public virtual void Serialize(ISerializationWriter writer) {
68+
_ = writer ?? throw new ArgumentNullException(nameof(writer));
69+
writer.WriteStringValue("describedby", Describedby);
70+
writer.WriteStringValue("self", Self);
71+
}
72+
}
73+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
using System.ComponentModel.DataAnnotations;
22
using System.Text.Json.Serialization;
33
using JetBrains.Annotations;
4+
using JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
45
using JsonApiDotNetCore.Serialization.Objects;
56

67
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents;
78

89
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
910
internal sealed class ErrorResponseDocument
1011
{
12+
[JsonPropertyName("jsonapi")]
13+
public Jsonapi Jsonapi { get; set; } = null!;
14+
15+
[Required]
16+
[JsonPropertyName("links")]
17+
public LinksInErrorDocument Links { get; set; } = null!;
18+
1119
[Required]
1220
[JsonPropertyName("errors")]
1321
public IList<ErrorObject> Errors { get; set; } = new List<ErrorObject>();
22+
23+
[JsonPropertyName("meta")]
24+
public IDictionary<string, object> Meta { get; set; } = null!;
1425
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
3+
using JetBrains.Annotations;
4+
5+
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
6+
7+
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
8+
internal sealed class LinksInErrorDocument
9+
{
10+
[Required]
11+
[JsonPropertyName("self")]
12+
public string Self { get; set; } = null!;
13+
14+
[JsonPropertyName("describedby")]
15+
public string Describedby { get; set; } = null!;
16+
}

src/JsonApiDotNetCore.OpenApi/JsonApiRequestFormatMetadataProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public IReadOnlyList<string> GetSupportedContentTypes(string contentType, Type o
3636
ArgumentGuard.NotNullNorEmpty(contentType);
3737
ArgumentGuard.NotNull(objectType);
3838

39-
if (contentType == HeaderConstants.MediaType && objectType.IsGenericType && JsonApiRequestOpenTypes.Contains(objectType.GetGenericTypeDefinition()))
39+
if (contentType == HeaderConstants.MediaType && objectType.IsConstructedGenericType &&
40+
JsonApiRequestOpenTypes.Contains(objectType.GetGenericTypeDefinition()))
4041
{
4142
return new MediaTypeCollection
4243
{

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/DocumentSchemaGenerator.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ public OpenApiSchema GenerateSchema(Type modelType, SchemaRepository schemaRepos
5959
ArgumentGuard.NotNull(modelType);
6060
ArgumentGuard.NotNull(schemaRepository);
6161

62-
OpenApiSchema referenceSchemaForDocument = GenerateJsonApiDocumentSchema(modelType, schemaRepository);
63-
OpenApiSchema fullSchemaForDocument = schemaRepository.Schemas[referenceSchemaForDocument.Reference.Id];
62+
OpenApiSchema referenceSchemaForDocument = modelType.IsConstructedGenericType
63+
? GenerateJsonApiDocumentSchema(modelType, schemaRepository)
64+
: _defaultSchemaGenerator.GenerateSchema(modelType, schemaRepository);
6465

65-
if (IsDataPropertyNullableInDocument(modelType))
66-
{
67-
SetDataSchemaToNullable(fullSchemaForDocument);
68-
}
66+
OpenApiSchema fullSchemaForDocument = schemaRepository.Schemas[referenceSchemaForDocument.Reference.Id];
6967

7068
fullSchemaForDocument.SetValuesInMetaToNullable();
7169

@@ -97,6 +95,11 @@ private OpenApiSchema GenerateJsonApiDocumentSchema(Type documentType, SchemaRep
9795
? CreateArrayTypeDataSchema(referenceSchemaForResourceData)
9896
: CreateExtendedReferenceSchema(referenceSchemaForResourceData);
9997

98+
if (IsDataPropertyNullableInDocument(documentType))
99+
{
100+
SetDataSchemaToNullable(fullSchemaForDocument);
101+
}
102+
100103
fullSchemaForDocument.ReorderProperties(DocumentPropertyNamesInOrder);
101104

102105
return referenceSchemaForDocument;

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JsonApiDotNetCore.OpenApi.SwaggerComponents;
1010

1111
internal sealed class JsonApiSchemaGenerator : ISchemaGenerator
1212
{
13-
private static readonly Type[] JsonApiDocumentOpenTypes =
13+
private static readonly Type[] JsonApiDocumentTypes =
1414
[
1515
typeof(ResourceCollectionResponseDocument<>),
1616
typeof(PrimaryResourceResponseDocument<>),
@@ -20,7 +20,8 @@ internal sealed class JsonApiSchemaGenerator : ISchemaGenerator
2020
typeof(ResourcePatchRequestDocument<>),
2121
typeof(ResourceIdentifierCollectionResponseDocument<>),
2222
typeof(ResourceIdentifierResponseDocument<>),
23-
typeof(NullableResourceIdentifierResponseDocument<>)
23+
typeof(NullableResourceIdentifierResponseDocument<>),
24+
typeof(ErrorResponseDocument)
2425
];
2526

2627
private static readonly OpenApiSchema IdTypeSchema = new()
@@ -77,6 +78,7 @@ private static bool IsJsonApiParameter(ParameterInfo parameter)
7778

7879
private static bool IsJsonApiDocument(Type type)
7980
{
80-
return type.IsConstructedGenericType && JsonApiDocumentOpenTypes.Contains(type.GetGenericTypeDefinition());
81+
Type documentType = type.IsConstructedGenericType ? type.GetGenericTypeDefinition() : type;
82+
return JsonApiDocumentTypes.Contains(documentType);
8183
}
8284
}

0 commit comments

Comments
 (0)