-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrorResponse.cs
More file actions
237 lines (205 loc) · 8.63 KB
/
ErrorResponse.cs
File metadata and controls
237 lines (205 loc) · 8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// <auto-generated>
/*
* DocSpring API
*
* Use DocSpring's API to programmatically fill out PDF forms, convert HTML to PDFs, merge PDFs, or request legally binding e-signatures.
*
* The version of the OpenAPI document: v1
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.ComponentModel.DataAnnotations;
using DocSpring.Client.Client;
namespace DocSpring.Client.Model
{
/// <summary>
/// ErrorResponse
/// </summary>
public partial class ErrorResponse : IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="ErrorResponse" /> class.
/// </summary>
/// <param name="status">status</param>
/// <param name="error">error</param>
[JsonConstructor]
public ErrorResponse(StatusEnum status, string error)
{
this.status = status;
this.error = error;
OnCreated();
}
partial void OnCreated();
/// <summary>
/// Defines status
/// </summary>
public enum StatusEnum
{
/// <summary>
/// Enum Error for value: error
/// </summary>
Error = 1
}
/// <summary>
/// Returns a <see cref="StatusEnum"/>
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static StatusEnum StatusEnumFromString(string value)
{
if (value.Equals("error"))
return StatusEnum.Error;
throw new NotImplementedException($"Could not convert value to type StatusEnum: '{value}'");
}
/// <summary>
/// Returns a <see cref="StatusEnum"/>
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static StatusEnum? StatusEnumFromStringOrDefault(string value)
{
if (value.Equals("error"))
return StatusEnum.Error;
return null;
}
/// <summary>
/// Converts the <see cref="StatusEnum"/> to the json value
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static string StatusEnumToJsonValue(StatusEnum value)
{
if (value == StatusEnum.Error)
return "error";
throw new NotImplementedException($"Value could not be handled: '{value}'");
}
/// <summary>
/// Gets or Sets status
/// </summary>
[JsonPropertyName("status")]
public StatusEnum status { get; set; }
/// <summary>
/// Gets or Sets error
/// </summary>
[JsonPropertyName("error")]
public string error { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class ErrorResponse {\n");
sb.Append(" status: ").Append(status).Append("\n");
sb.Append(" error: ").Append(error).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
yield break;
}
}
/// <summary>
/// A Json converter for type <see cref="ErrorResponse" />
/// </summary>
public class ErrorResponseJsonConverter : JsonConverter<ErrorResponse>
{
/// <summary>
/// Deserializes json to <see cref="ErrorResponse" />
/// </summary>
/// <param name="utf8JsonReader"></param>
/// <param name="typeToConvert"></param>
/// <param name="jsonSerializerOptions"></param>
/// <returns></returns>
/// <exception cref="JsonException"></exception>
public override ErrorResponse Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
{
int currentDepth = utf8JsonReader.CurrentDepth;
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
throw new JsonException();
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Option<ErrorResponse.StatusEnum?> status = default;
Option<string> error = default;
while (utf8JsonReader.Read())
{
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
break;
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
break;
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
{
string localVarJsonPropertyName = utf8JsonReader.GetString();
utf8JsonReader.Read();
switch (localVarJsonPropertyName)
{
case "status":
string statusRawValue = utf8JsonReader.GetString();
if (statusRawValue != null)
status = new Option<ErrorResponse.StatusEnum?>(ErrorResponse.StatusEnumFromStringOrDefault(statusRawValue));
break;
case "error":
error = new Option<string>(utf8JsonReader.GetString());
break;
default:
break;
}
}
}
if (!status.IsSet)
throw new ArgumentException("Property is required for class ErrorResponse.", nameof(status));
if (!error.IsSet)
throw new ArgumentException("Property is required for class ErrorResponse.", nameof(error));
if (status.IsSet && status.Value == null)
throw new ArgumentNullException(nameof(status), "Property is not nullable for class ErrorResponse.");
if (error.IsSet && error.Value == null)
throw new ArgumentNullException(nameof(error), "Property is not nullable for class ErrorResponse.");
return new ErrorResponse(status.Value.Value, error.Value);
}
/// <summary>
/// Serializes a <see cref="ErrorResponse" />
/// </summary>
/// <param name="writer"></param>
/// <param name="errorResponse"></param>
/// <param name="jsonSerializerOptions"></param>
/// <exception cref="NotImplementedException"></exception>
public override void Write(Utf8JsonWriter writer, ErrorResponse errorResponse, JsonSerializerOptions jsonSerializerOptions)
{
writer.WriteStartObject();
WriteProperties(writer, errorResponse, jsonSerializerOptions);
writer.WriteEndObject();
}
/// <summary>
/// Serializes the properties of <see cref="ErrorResponse" />
/// </summary>
/// <param name="writer"></param>
/// <param name="errorResponse"></param>
/// <param name="jsonSerializerOptions"></param>
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, ErrorResponse errorResponse, JsonSerializerOptions jsonSerializerOptions)
{
if (errorResponse.error == null)
throw new ArgumentNullException(nameof(errorResponse.error), "Property is required for class ErrorResponse.");
var statusRawValue = ErrorResponse.StatusEnumToJsonValue(errorResponse.status);
writer.WriteString("status", statusRawValue);
writer.WriteString("error", errorResponse.error);
}
}
}