|
26 | 26 | namespace Org.OpenAPITools.Model |
27 | 27 | { |
28 | 28 | /// <summary> |
29 | | - /// AreaCode |
| 29 | + /// Defines AreaCode |
30 | 30 | /// </summary> |
31 | | - public partial class AreaCode : IValidatableObject |
| 31 | + public enum AreaCode |
32 | 32 | { |
33 | 33 | /// <summary> |
34 | | - /// Initializes a new instance of the <see cref="AreaCode" /> class. |
| 34 | + /// Enum AL for value: AL |
35 | 35 | /// </summary> |
36 | | - /// <param name="stateTerritoryCode"></param> |
37 | | - internal AreaCode(StateTerritoryCode stateTerritoryCode) |
38 | | - { |
39 | | - StateTerritoryCode = stateTerritoryCode; |
40 | | - OnCreated(); |
41 | | - } |
| 36 | + AL = 1, |
42 | 37 |
|
43 | 38 | /// <summary> |
44 | | - /// Initializes a new instance of the <see cref="AreaCode" /> class. |
| 39 | + /// Enum AK for value: AK |
45 | 40 | /// </summary> |
46 | | - /// <param name="marineAreaCode"></param> |
47 | | - internal AreaCode(MarineAreaCode marineAreaCode) |
48 | | - { |
49 | | - MarineAreaCode = marineAreaCode; |
50 | | - OnCreated(); |
51 | | - } |
| 41 | + AK = 2, |
52 | 42 |
|
53 | | - partial void OnCreated(); |
| 43 | + /// <summary> |
| 44 | + /// Enum AM for value: AM |
| 45 | + /// </summary> |
| 46 | + AM = 3, |
54 | 47 |
|
55 | 48 | /// <summary> |
56 | | - /// Gets or Sets StateTerritoryCode |
| 49 | + /// Enum AN for value: AN |
57 | 50 | /// </summary> |
58 | | - public StateTerritoryCode? StateTerritoryCode { get; set; } |
| 51 | + AN = 4 |
| 52 | + } |
59 | 53 |
|
| 54 | + /// <summary> |
| 55 | + /// Converts <see cref="AreaCode"/> to and from the JSON value |
| 56 | + /// </summary> |
| 57 | + public static class AreaCodeValueConverter |
| 58 | + { |
60 | 59 | /// <summary> |
61 | | - /// Gets or Sets MarineAreaCode |
| 60 | + /// Parses a given value to <see cref="AreaCode"/> |
62 | 61 | /// </summary> |
63 | | - public MarineAreaCode? MarineAreaCode { get; set; } |
| 62 | + /// <param name="value"></param> |
| 63 | + /// <returns></returns> |
| 64 | + public static AreaCode FromString(string value) |
| 65 | + { |
| 66 | + if (value.Equals("AL")) |
| 67 | + return AreaCode.AL; |
| 68 | + |
| 69 | + if (value.Equals("AK")) |
| 70 | + return AreaCode.AK; |
| 71 | + |
| 72 | + if (value.Equals("AM")) |
| 73 | + return AreaCode.AM; |
| 74 | + |
| 75 | + if (value.Equals("AN")) |
| 76 | + return AreaCode.AN; |
| 77 | + |
| 78 | + throw new NotImplementedException($"Could not convert value to type AreaCode: '{value}'"); |
| 79 | + } |
64 | 80 |
|
65 | 81 | /// <summary> |
66 | | - /// Returns the string presentation of the object |
| 82 | + /// Parses a given value to <see cref="AreaCode"/> |
67 | 83 | /// </summary> |
68 | | - /// <returns>String presentation of the object</returns> |
69 | | - public override string ToString() |
| 84 | + /// <param name="value"></param> |
| 85 | + /// <returns></returns> |
| 86 | + public static AreaCode? FromStringOrDefault(string value) |
70 | 87 | { |
71 | | - StringBuilder sb = new StringBuilder(); |
72 | | - sb.Append("class AreaCode {\n"); |
73 | | - sb.Append("}\n"); |
74 | | - return sb.ToString(); |
| 88 | + if (value.Equals("AL")) |
| 89 | + return AreaCode.AL; |
| 90 | + |
| 91 | + if (value.Equals("AK")) |
| 92 | + return AreaCode.AK; |
| 93 | + |
| 94 | + if (value.Equals("AM")) |
| 95 | + return AreaCode.AM; |
| 96 | + |
| 97 | + if (value.Equals("AN")) |
| 98 | + return AreaCode.AN; |
| 99 | + |
| 100 | + return null; |
75 | 101 | } |
76 | 102 |
|
77 | 103 | /// <summary> |
78 | | - /// To validate all properties of the instance |
| 104 | + /// Converts the <see cref="AreaCode"/> to the json value |
79 | 105 | /// </summary> |
80 | | - /// <param name="validationContext">Validation context</param> |
81 | | - /// <returns>Validation Result</returns> |
82 | | - IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) |
| 106 | + /// <param name="value"></param> |
| 107 | + /// <returns></returns> |
| 108 | + /// <exception cref="NotImplementedException"></exception> |
| 109 | + public static string ToJsonValue(AreaCode value) |
83 | 110 | { |
84 | | - yield break; |
| 111 | + if (value == AreaCode.AL) |
| 112 | + return "AL"; |
| 113 | + |
| 114 | + if (value == AreaCode.AK) |
| 115 | + return "AK"; |
| 116 | + |
| 117 | + if (value == AreaCode.AM) |
| 118 | + return "AM"; |
| 119 | + |
| 120 | + if (value == AreaCode.AN) |
| 121 | + return "AN"; |
| 122 | + |
| 123 | + throw new NotImplementedException($"Value could not be handled: '{value}'"); |
85 | 124 | } |
86 | 125 | } |
87 | 126 |
|
88 | 127 | /// <summary> |
89 | | - /// A Json converter for type <see cref="AreaCode" /> |
| 128 | + /// A Json converter for type <see cref="AreaCode"/> |
90 | 129 | /// </summary> |
| 130 | + /// <exception cref="NotImplementedException"></exception> |
91 | 131 | public class AreaCodeJsonConverter : JsonConverter<AreaCode> |
92 | 132 | { |
93 | 133 | /// <summary> |
94 | | - /// Deserializes json to <see cref="AreaCode" /> |
| 134 | + /// Returns a from the Json object |
95 | 135 | /// </summary> |
96 | | - /// <param name="utf8JsonReader"></param> |
| 136 | + /// <param name="reader"></param> |
97 | 137 | /// <param name="typeToConvert"></param> |
98 | | - /// <param name="jsonSerializerOptions"></param> |
| 138 | + /// <param name="options"></param> |
99 | 139 | /// <returns></returns> |
100 | | - /// <exception cref="JsonException"></exception> |
101 | | - public override AreaCode Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) |
| 140 | + public override AreaCode Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
102 | 141 | { |
103 | | - int currentDepth = utf8JsonReader.CurrentDepth; |
| 142 | + string? rawValue = reader.GetString(); |
104 | 143 |
|
105 | | - if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) |
106 | | - throw new JsonException(); |
| 144 | + AreaCode? result = rawValue == null |
| 145 | + ? null |
| 146 | + : AreaCodeValueConverter.FromStringOrDefault(rawValue); |
107 | 147 |
|
108 | | - JsonTokenType startingTokenType = utf8JsonReader.TokenType; |
109 | | - |
110 | | - StateTerritoryCode? stateTerritoryCode = default; |
111 | | - MarineAreaCode? marineAreaCode = default; |
112 | | - |
113 | | - Utf8JsonReader utf8JsonReaderOneOf = utf8JsonReader; |
114 | | - while (utf8JsonReaderOneOf.Read()) |
115 | | - { |
116 | | - if (startingTokenType == JsonTokenType.StartObject && utf8JsonReaderOneOf.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReaderOneOf.CurrentDepth) |
117 | | - break; |
118 | | - |
119 | | - if (startingTokenType == JsonTokenType.StartArray && utf8JsonReaderOneOf.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReaderOneOf.CurrentDepth) |
120 | | - break; |
121 | | - |
122 | | - if (utf8JsonReaderOneOf.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReaderOneOf.CurrentDepth - 1) |
123 | | - { |
124 | | - Utf8JsonReader utf8JsonReaderStateTerritoryCode = utf8JsonReader; |
125 | | - ClientUtils.TryDeserialize<StateTerritoryCode?>(ref utf8JsonReaderStateTerritoryCode, jsonSerializerOptions, out stateTerritoryCode); |
126 | | - |
127 | | - Utf8JsonReader utf8JsonReaderMarineAreaCode = utf8JsonReader; |
128 | | - ClientUtils.TryDeserialize<MarineAreaCode?>(ref utf8JsonReaderMarineAreaCode, jsonSerializerOptions, out marineAreaCode); |
129 | | - } |
130 | | - } |
131 | | - |
132 | | - while (utf8JsonReader.Read()) |
133 | | - { |
134 | | - if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) |
135 | | - break; |
136 | | - |
137 | | - if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) |
138 | | - break; |
139 | | - |
140 | | - if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) |
141 | | - { |
142 | | - string? localVarJsonPropertyName = utf8JsonReader.GetString(); |
143 | | - utf8JsonReader.Read(); |
144 | | - |
145 | | - switch (localVarJsonPropertyName) |
146 | | - { |
147 | | - default: |
148 | | - break; |
149 | | - } |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - if (stateTerritoryCode != null) |
154 | | - return new AreaCode(stateTerritoryCode.Value); |
155 | | - |
156 | | - if (marineAreaCode != null) |
157 | | - return new AreaCode(marineAreaCode.Value); |
| 148 | + if (result != null) |
| 149 | + return result.Value; |
158 | 150 |
|
159 | 151 | throw new JsonException(); |
160 | 152 | } |
161 | 153 |
|
162 | 154 | /// <summary> |
163 | | - /// Serializes a <see cref="AreaCode" /> |
| 155 | + /// Writes the AreaCode to the json writer |
164 | 156 | /// </summary> |
165 | 157 | /// <param name="writer"></param> |
166 | 158 | /// <param name="areaCode"></param> |
167 | | - /// <param name="jsonSerializerOptions"></param> |
168 | | - /// <exception cref="NotImplementedException"></exception> |
169 | | - public override void Write(Utf8JsonWriter writer, AreaCode areaCode, JsonSerializerOptions jsonSerializerOptions) |
| 159 | + /// <param name="options"></param> |
| 160 | + public override void Write(Utf8JsonWriter writer, AreaCode areaCode, JsonSerializerOptions options) |
| 161 | + { |
| 162 | + writer.WriteStringValue(AreaCodeValueConverter.ToJsonValue(areaCode).ToString()); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + /// <summary> |
| 167 | + /// A Json converter for type <see cref="AreaCode"/> |
| 168 | + /// </summary> |
| 169 | + public class AreaCodeNullableJsonConverter : JsonConverter<AreaCode?> |
| 170 | + { |
| 171 | + /// <summary> |
| 172 | + /// Returns a AreaCode from the Json object |
| 173 | + /// </summary> |
| 174 | + /// <param name="reader"></param> |
| 175 | + /// <param name="typeToConvert"></param> |
| 176 | + /// <param name="options"></param> |
| 177 | + /// <returns></returns> |
| 178 | + public override AreaCode? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
170 | 179 | { |
171 | | - writer.WriteStartObject(); |
| 180 | + string? rawValue = reader.GetString(); |
| 181 | + |
| 182 | + AreaCode? result = rawValue == null |
| 183 | + ? null |
| 184 | + : AreaCodeValueConverter.FromStringOrDefault(rawValue); |
| 185 | + |
| 186 | + if (result != null) |
| 187 | + return result.Value; |
172 | 188 |
|
173 | | - WriteProperties(writer, areaCode, jsonSerializerOptions); |
174 | | - writer.WriteEndObject(); |
| 189 | + throw new JsonException(); |
175 | 190 | } |
176 | 191 |
|
177 | 192 | /// <summary> |
178 | | - /// Serializes the properties of <see cref="AreaCode" /> |
| 193 | + /// Writes the AreaCode to the json writer |
179 | 194 | /// </summary> |
180 | 195 | /// <param name="writer"></param> |
181 | 196 | /// <param name="areaCode"></param> |
182 | | - /// <param name="jsonSerializerOptions"></param> |
183 | | - /// <exception cref="NotImplementedException"></exception> |
184 | | - public void WriteProperties(Utf8JsonWriter writer, AreaCode areaCode, JsonSerializerOptions jsonSerializerOptions) |
| 197 | + /// <param name="options"></param> |
| 198 | + public override void Write(Utf8JsonWriter writer, AreaCode? areaCode, JsonSerializerOptions options) |
185 | 199 | { |
186 | | - |
| 200 | + writer.WriteStringValue(areaCode.HasValue ? AreaCodeValueConverter.ToJsonValue(areaCode.Value).ToString() : "null"); |
187 | 201 | } |
188 | 202 | } |
189 | 203 | } |
0 commit comments