11using System . Text . Json . Serialization ;
22
3+ #nullable enable
4+
35namespace FluentRest ;
46
57/// <summary>
68/// A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
79/// </summary>
8- [ JsonConverter ( typeof ( ProblemDetailsConverter ) ) ]
910public class ProblemDetails
1011{
1112 /// <summary>
@@ -14,43 +15,67 @@ public class ProblemDetails
1415 public const string ContentType = "application/problem+json" ;
1516
1617 /// <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".
1822 /// </summary>
1923 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
24+ [ JsonPropertyOrder ( - 5 ) ]
2025 [ JsonPropertyName ( "type" ) ]
21- public string Type { get ; set ; }
26+ public string ? Type { get ; set ; }
2227
2328 /// <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).
2532 /// </summary>
2633 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
34+ [ JsonPropertyOrder ( - 4 ) ]
2735 [ JsonPropertyName ( "title" ) ]
28- public string Title { get ; set ; }
36+ public string ? Title { get ; set ; }
2937
3038 /// <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.
3240 /// </summary>
3341 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
42+ [ JsonPropertyOrder ( - 3 ) ]
3443 [ JsonPropertyName ( "status" ) ]
3544 public int ? Status { get ; set ; }
3645
3746 /// <summary>
3847 /// A human-readable explanation specific to this occurrence of the problem.
3948 /// </summary>
4049 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
50+ [ JsonPropertyOrder ( - 2 ) ]
4151 [ JsonPropertyName ( "detail" ) ]
42- public string Detail { get ; set ; }
52+ public string ? Detail { get ; set ; }
4353
4454 /// <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.
4656 /// </summary>
4757 [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
58+ [ JsonPropertyOrder ( - 1 ) ]
4859 [ 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 ) ;
5067
5168 /// <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>
5374 /// </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>
5479 [ 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 ) ;
5681}
0 commit comments