|
6 | 6 | using System.Collections.Generic; |
7 | 7 | using System.Linq; |
8 | 8 | using ApiGenerator.Generator; |
| 9 | +using Newtonsoft.Json; |
| 10 | +using Newtonsoft.Json.Linq; |
9 | 11 |
|
10 | 12 | namespace ApiGenerator.Domain.Specification |
11 | 13 | { |
@@ -74,21 +76,23 @@ public string Obsolete |
74 | 76 | get |
75 | 77 | { |
76 | 78 | if (!string.IsNullOrEmpty(_obsolete)) return _obsolete; |
| 79 | + if (Deprecated != null) |
| 80 | + { |
| 81 | + if (!string.IsNullOrEmpty(Deprecated.Version) && !string.IsNullOrEmpty(Deprecated.Description)) |
| 82 | + return $"Deprecated as of: {Deprecated.Version}, reason: {Deprecated.Description}"; |
| 83 | + if (!string.IsNullOrEmpty(Deprecated.Version)) |
| 84 | + return $"Deprecated as of: {Deprecated.Version}"; |
| 85 | + if (!string.IsNullOrEmpty(Deprecated.Description)) |
| 86 | + return $"reason: {Deprecated.Description}"; |
| 87 | + |
| 88 | + return "deprecated"; |
| 89 | + } |
77 | 90 |
|
78 | | - return Deprecated != null |
79 | | - ? $"Deprecated as of: {Deprecated.Version}, reason: {Deprecated.Description}" |
80 | | - : null; |
| 91 | + return null; |
81 | 92 | } |
82 | 93 | set => _obsolete = value; |
83 | 94 | } |
84 | 95 |
|
85 | | - public class QueryParameterDeprecation |
86 | | - { |
87 | | - public string Version { get; set; } |
88 | | - |
89 | | - public string Description { get; set; } |
90 | | - } |
91 | | - |
92 | 96 | public QueryParameterDeprecation Deprecated { get; set; } |
93 | 97 |
|
94 | 98 | public IEnumerable<string> Options { get; set; } |
@@ -168,4 +172,27 @@ public string TypeLowLevel |
168 | 172 | public string InitializerGenerator(string @namespace, string type, string name, string key, string setter, params string[] doc) => |
169 | 173 | CodeGenerator.Property(@namespace, type, name, key, setter, Obsolete, doc); |
170 | 174 | } |
| 175 | + |
| 176 | + public class QueryParameterDeprecation |
| 177 | + { |
| 178 | + public string Version { get; set; } |
| 179 | + |
| 180 | + public string Description { get; set; } |
| 181 | + } |
| 182 | + |
| 183 | + internal class QueryParameterDeprecationConverter : JsonConverter |
| 184 | + { |
| 185 | + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); |
| 186 | + |
| 187 | + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) |
| 188 | + { |
| 189 | + if (reader.TokenType == JsonToken.Boolean) |
| 190 | + return new QueryParameterDeprecation(); |
| 191 | + |
| 192 | + var jObject = JObject.Load(reader); |
| 193 | + return jObject.ToObject<QueryParameterDeprecation>(JsonSerializer.CreateDefault()); |
| 194 | + } |
| 195 | + |
| 196 | + public override bool CanConvert(Type objectType) => typeof(QueryParameterDeprecation).IsAssignableFrom(objectType); |
| 197 | + } |
171 | 198 | } |
0 commit comments