1
1
using System . Text . Json . Serialization ;
2
2
3
+ #nullable enable
4
+
3
5
namespace FluentRest ;
4
6
5
7
/// <summary>
6
8
/// A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
7
9
/// </summary>
8
- [ JsonConverter ( typeof ( ProblemDetailsConverter ) ) ]
9
10
public class ProblemDetails
10
11
{
11
12
/// <summary>
@@ -14,43 +15,67 @@ public class ProblemDetails
14
15
public const string ContentType = "application/problem+json" ;
15
16
16
17
/// <summary>
17
- /// A URI reference that identifies the problem type.
18
+ /// A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when
19
+ /// dereferenced, it provide human-readable documentation for the problem type
20
+ /// (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be
21
+ /// "about:blank".
18
22
/// </summary>
19
23
[ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
24
+ [ JsonPropertyOrder ( - 5 ) ]
20
25
[ JsonPropertyName ( "type" ) ]
21
- public string Type { get ; set ; }
26
+ public string ? Type { get ; set ; }
22
27
23
28
/// <summary>
24
- /// A short, human-readable summary of the problem type.
29
+ /// A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence
30
+ /// of the problem, except for purposes of localization(e.g., using proactive content negotiation;
31
+ /// see[RFC7231], Section 3.4).
25
32
/// </summary>
26
33
[ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
34
+ [ JsonPropertyOrder ( - 4 ) ]
27
35
[ JsonPropertyName ( "title" ) ]
28
- public string Title { get ; set ; }
36
+ public string ? Title { get ; set ; }
29
37
30
38
/// <summary>
31
- /// The HTTP status code generated by the origin server for this occurrence of the problem.
39
+ /// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
32
40
/// </summary>
33
41
[ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
42
+ [ JsonPropertyOrder ( - 3 ) ]
34
43
[ JsonPropertyName ( "status" ) ]
35
44
public int ? Status { get ; set ; }
36
45
37
46
/// <summary>
38
47
/// A human-readable explanation specific to this occurrence of the problem.
39
48
/// </summary>
40
49
[ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
50
+ [ JsonPropertyOrder ( - 2 ) ]
41
51
[ JsonPropertyName ( "detail" ) ]
42
- public string Detail { get ; set ; }
52
+ public string ? Detail { get ; set ; }
43
53
44
54
/// <summary>
45
- /// A URI reference that identifies the specific occurrence of the problem.
55
+ /// A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
46
56
/// </summary>
47
57
[ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
58
+ [ JsonPropertyOrder ( - 1 ) ]
48
59
[ JsonPropertyName ( "instance" ) ]
49
- public string Instance { get ; set ; }
60
+ public string ? Instance { get ; set ; }
61
+
62
+ /// <summary>
63
+ /// Gets the validation errors associated with this instance of problem details
64
+ /// </summary>
65
+ [ JsonPropertyName ( "errors" ) ]
66
+ public IDictionary < string , string [ ] > Errors { get ; set ; } = new Dictionary < string , string [ ] > ( StringComparer . Ordinal ) ;
50
67
51
68
/// <summary>
52
- /// Problem type definitions MAY extend the problem details object with additional members.
69
+ /// Gets the <see cref="IDictionary{TKey, TValue}"/> for extension members.
70
+ /// <para>
71
+ /// Problem type definitions MAY extend the problem details object with additional members. Extension members appear in the same namespace as
72
+ /// other members of a problem type.
73
+ /// </para>
53
74
/// </summary>
75
+ /// <remarks>
76
+ /// The round-tripping behavior for <see cref="Extensions"/> is determined by the implementation of the Input \ Output formatters.
77
+ /// In particular, complex types or collection types may not round-trip to the original type when using the built-in JSON or XML formatters.
78
+ /// </remarks>
54
79
[ JsonExtensionData ]
55
- public IDictionary < string , object > Extensions { get ; } = new Dictionary < string , object > ( StringComparer . Ordinal ) ;
80
+ public IDictionary < string , object ? > Extensions { get ; set ; } = new Dictionary < string , object ? > ( StringComparer . Ordinal ) ;
56
81
}
0 commit comments