|
1 | 1 | @using Elastic.ApiExplorer.Landing |
2 | 2 | @using Elastic.ApiExplorer.Operations |
3 | 3 | @using Microsoft.OpenApi.Models |
| 4 | +@using Microsoft.OpenApi.Models.Interfaces |
4 | 5 | @inherits RazorSliceHttpResult<Elastic.ApiExplorer.Operations.OperationViewModel> |
5 | 6 | @implements IUsesLayout<Elastic.ApiExplorer._Layout, GlobalLayoutViewModel> |
6 | 7 | @functions { |
7 | 8 | public GlobalLayoutViewModel LayoutModel => Model.CreateGlobalLayoutModel(); |
| 9 | + |
| 10 | + public string GetTypeName(JsonSchemaType? type) |
| 11 | + { |
| 12 | + var typeName = ""; |
| 13 | + if (type is null) |
| 14 | + return "unknown and null"; |
| 15 | + |
| 16 | + if (type.Value.HasFlag(JsonSchemaType.Boolean)) |
| 17 | + typeName = "boolean"; |
| 18 | + else if (type.Value.HasFlag(JsonSchemaType.Integer)) |
| 19 | + typeName = "integer"; |
| 20 | + else if (type.Value.HasFlag(JsonSchemaType.String)) |
| 21 | + typeName = "string"; |
| 22 | + else if (type.Value.HasFlag(JsonSchemaType.Object)) |
| 23 | + { |
| 24 | + typeName = "object"; |
| 25 | + } |
| 26 | + else if (type.Value.HasFlag(JsonSchemaType.Null)) |
| 27 | + typeName = "null"; |
| 28 | + else if (type.Value.HasFlag(JsonSchemaType.Number)) |
| 29 | + typeName = "number"; |
| 30 | + else |
| 31 | + { |
| 32 | + } |
| 33 | + |
| 34 | + if (type.Value.HasFlag(JsonSchemaType.Array)) |
| 35 | + typeName += " array"; |
| 36 | + return typeName; |
| 37 | + } |
| 38 | + |
| 39 | + public string GetTypeName(IOpenApiSchema propertyValue) |
| 40 | + { |
| 41 | + var typeName = string.Empty; |
| 42 | + if (propertyValue.Type is not null) |
| 43 | + { |
| 44 | + typeName = GetTypeName(propertyValue.Type); |
| 45 | + if (typeName is not "object" and not "array") |
| 46 | + return typeName; |
| 47 | + } |
| 48 | + |
| 49 | + if (propertyValue.Schema is not null) |
| 50 | + return propertyValue.Schema; |
| 51 | + |
| 52 | + if (propertyValue.Enum is { Count: >0 } e) |
| 53 | + return "enum"; |
| 54 | + |
| 55 | + return $"unknown value {typeName}"; |
| 56 | + } |
8 | 57 | } |
9 | 58 | @{ |
10 | 59 | var self = Model.CurrentNavigationItem as OperationNavigationItem; |
|
72 | 121 | @if (operation.RequestBody is not null) |
73 | 122 | { |
74 | 123 | <h3>Request Body</h3> |
| 124 | + var content = operation.RequestBody.Content.FirstOrDefault().Value; |
75 | 125 | if (!string.IsNullOrEmpty(operation.RequestBody.Description)) |
76 | 126 | { |
77 | 127 | <p>@operation.RequestBody.Description</p> |
78 | 128 | } |
| 129 | + |
| 130 | + if (content.Schema is not null) |
| 131 | + { |
79 | 132 | <dl> |
80 | | - @foreach (var path in operation.RequestBody.Content) |
| 133 | + @foreach (var property in content.Schema.Properties) |
81 | 134 | { |
| 135 | + if (property.Value.Type is null) |
| 136 | + { |
| 137 | + |
| 138 | + } |
| 139 | + <dt id="@property.Key"><a href="#@property.Key"><code>@property.Key</code> @GetTypeName(property.Value) </a></dt> |
| 140 | + <dd>@Model.RenderMarkdown(property.Value.Description)</dd> |
82 | 141 | } |
83 | 142 | </dl> |
| 143 | + } |
84 | 144 | } |
85 | 145 | </section> |
86 | 146 | <aside> |
|
0 commit comments