|
1 | | -using MicroBatchFramework.WebHosting.Swagger.Schemas; |
| 1 | +using MicroBatchFramework.WebHosting.Swagger.Schemas; |
2 | 2 | using Microsoft.AspNetCore.Http; |
3 | 3 | using Newtonsoft.Json; |
4 | 4 | using Newtonsoft.Json.Serialization; |
@@ -44,13 +44,15 @@ public byte[] BuildSwaggerJson() |
44 | 44 | : null; |
45 | 45 | } |
46 | 46 |
|
47 | | - var doc = new SwaggerDocument(); |
48 | | - doc.info = options.Info; |
49 | | - doc.host = (options.CustomHost != null) ? options.CustomHost(httpContext) : httpContext.Request.Headers["Host"][0]; |
50 | | - doc.basePath = options.ApiBasePath; |
51 | | - doc.schemes = (options.ForceSchemas.Length == 0) ? new[] { httpContext.Request.IsHttps ? "https" : httpContext.Request.Scheme } : options.ForceSchemas; |
52 | | - doc.paths = new Dictionary<string, PathItem>(); |
53 | | - doc.definitions = new Dictionary<string, Schema>(); |
| 47 | + var doc = new SwaggerDocument |
| 48 | + { |
| 49 | + info = options.Info, |
| 50 | + host = (options.CustomHost != null) ? options.CustomHost(httpContext) : httpContext.Request.Headers["Host"][0], |
| 51 | + basePath = options.ApiBasePath, |
| 52 | + schemes = (options.ForceSchemas.Length == 0) ? new[] { httpContext.Request.IsHttps ? "https" : httpContext.Request.Scheme } : options.ForceSchemas, |
| 53 | + paths = new Dictionary<string, PathItem>(), |
| 54 | + definitions = new Dictionary<string, Schema>() |
| 55 | + }; |
54 | 56 |
|
55 | 57 | // tags. |
56 | 58 | var xmlServiceName = (xDocLookup != null) |
@@ -203,8 +205,7 @@ string BuildSchema(IDictionary<string, Schema> definitions, Type type) |
203 | 205 | var fullName = type.FullName; |
204 | 206 | if (fullName == null) return ""; // safety(TODO:IDictionary<> is not supported) |
205 | 207 |
|
206 | | - Schema schema; |
207 | | - if (definitions.TryGetValue(fullName, out schema)) return "#/definitions/" + fullName; |
| 208 | + if (definitions.TryGetValue(fullName, out Schema schema)) return "#/definitions/" + fullName; |
208 | 209 |
|
209 | 210 | var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); |
210 | 211 | var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public); |
|
0 commit comments