|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text.Json.Serialization; |
| 4 | + |
| 5 | +namespace Certify.Models.Util |
| 6 | +{ |
| 7 | + // extracted from the following to avoid including MVC dependencies |
| 8 | + //https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http.Abstractions/src/ProblemDetails/ProblemDetails.cs |
| 9 | + // Licensed to the .NET Foundation under one or more agreements. |
| 10 | + // The .NET Foundation licenses this file to you under the MIT license. |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// A machine-readable format for specifying errors in HTTP API responses based on <see href="https://tools.ietf.org/html/rfc7807"/>. |
| 14 | + /// </summary> |
| 15 | + public class ProblemDetails |
| 16 | + { |
| 17 | + /// <summary> |
| 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". |
| 22 | + /// </summary> |
| 23 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 24 | + [JsonPropertyOrder(-5)] |
| 25 | + [JsonPropertyName("type")] |
| 26 | + public string? Type { get; set; } |
| 27 | + |
| 28 | + /// <summary> |
| 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). |
| 32 | + /// </summary> |
| 33 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 34 | + [JsonPropertyOrder(-4)] |
| 35 | + [JsonPropertyName("title")] |
| 36 | + public string? Title { get; set; } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem. |
| 40 | + /// </summary> |
| 41 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 42 | + [JsonPropertyOrder(-3)] |
| 43 | + [JsonPropertyName("status")] |
| 44 | + public int? Status { get; set; } |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// A human-readable explanation specific to this occurrence of the problem. |
| 48 | + /// </summary> |
| 49 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 50 | + [JsonPropertyOrder(-2)] |
| 51 | + [JsonPropertyName("detail")] |
| 52 | + public string? Detail { get; set; } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. |
| 56 | + /// </summary> |
| 57 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 58 | + [JsonPropertyOrder(-1)] |
| 59 | + [JsonPropertyName("instance")] |
| 60 | + public string? Instance { get; set; } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Gets the <see cref="IDictionary{TKey, TValue}"/> for extension members. |
| 64 | + /// <para> |
| 65 | + /// Problem type definitions MAY extend the problem details object with additional members. Extension members appear in the same namespace as |
| 66 | + /// other members of a problem type. |
| 67 | + /// </para> |
| 68 | + /// </summary> |
| 69 | + /// <remarks> |
| 70 | + /// The round-tripping behavior for <see cref="Extensions"/> is determined by the implementation of the Input \ Output formatters. |
| 71 | + /// In particular, complex types or collection types may not round-trip to the original type when using the built-in JSON or XML formatters. |
| 72 | + /// </remarks> |
| 73 | + [JsonExtensionData] |
| 74 | + public IDictionary<string, object?> Extensions { get; set; } = new Dictionary<string, object?>(StringComparer.Ordinal); |
| 75 | + } |
| 76 | +} |
0 commit comments