Skip to content

Commit 95a3780

Browse files
committed
work on typename exposure
1 parent e413e32 commit 95a3780

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<PackageVersion Include="Markdig" Version="0.41.1" />
4343
<PackageVersion Include="NetEscapades.EnumGenerators" Version="1.0.0-beta12" PrivateAssets="all" ExcludeAssets="runtime" />
4444
<PackageVersion Include="Proc" Version="0.9.1" />
45-
<PackageVersion Include="RazorSlices" Version="0.9.0" />
45+
<PackageVersion Include="RazorSlices" Version="0.9.2" />
4646
<PackageVersion Include="Samboy063.Tomlet" Version="6.0.0" />
4747
<PackageVersion Include="Slugify.Core" Version="4.0.1" />
4848
<PackageVersion Include="SoftCircuits.IniFileParser" Version="2.7.0" />

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
@using Elastic.ApiExplorer.Landing
22
@using Elastic.ApiExplorer.Operations
33
@using Microsoft.OpenApi.Models
4+
@using Microsoft.OpenApi.Models.Interfaces
45
@inherits RazorSliceHttpResult<Elastic.ApiExplorer.Operations.OperationViewModel>
56
@implements IUsesLayout<Elastic.ApiExplorer._Layout, GlobalLayoutViewModel>
67
@functions {
78
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+
}
857
}
958
@{
1059
var self = Model.CurrentNavigationItem as OperationNavigationItem;
@@ -72,15 +121,26 @@
72121
@if (operation.RequestBody is not null)
73122
{
74123
<h3>Request Body</h3>
124+
var content = operation.RequestBody.Content.FirstOrDefault().Value;
75125
if (!string.IsNullOrEmpty(operation.RequestBody.Description))
76126
{
77127
<p>@operation.RequestBody.Description</p>
78128
}
129+
130+
if (content.Schema is not null)
131+
{
79132
<dl>
80-
@foreach (var path in operation.RequestBody.Content)
133+
@foreach (var property in content.Schema.Properties)
81134
{
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>
82141
}
83142
</dl>
143+
}
84144
}
85145
</section>
86146
<aside>

src/tooling/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<!-- TODO ENABLE to document our code properly <GenerateDocumentationFile>true</GenerateDocumentationFile> -->
1111
<PublishRepositoryUrl>true</PublishRepositoryUrl>
12+
1213
</PropertyGroup>
1314

1415
<ItemGroup Condition="'$(OutputType)' == 'Exe'">
@@ -17,4 +18,4 @@
1718
<Content Include="$(SolutionRoot)\NOTICE.txt" Pack="True" PackagePath="NOTICE.txt" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest"/>
1819
</ItemGroup>
1920

20-
</Project>
21+
</Project>

src/tooling/docs-builder/Http/ReloadGeneratorService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to Elasticsearch B.V under one or more agreements.
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
4+
45
using Microsoft.Extensions.Hosting;
56
using Microsoft.Extensions.Logging;
67

@@ -25,12 +26,12 @@ public async Task StartAsync(Cancel cancellationToken)
2526
var watcher = new FileSystemWatcher(ReloadableGenerator.Generator.DocumentationSet.SourceDirectory.FullName)
2627
{
2728
NotifyFilter = NotifyFilters.Attributes
28-
| NotifyFilters.CreationTime
29-
| NotifyFilters.DirectoryName
30-
| NotifyFilters.FileName
31-
| NotifyFilters.LastWrite
32-
| NotifyFilters.Security
33-
| NotifyFilters.Size
29+
| NotifyFilters.CreationTime
30+
| NotifyFilters.DirectoryName
31+
| NotifyFilters.FileName
32+
| NotifyFilters.LastWrite
33+
| NotifyFilters.Security
34+
| NotifyFilters.Size
3435
};
3536

3637
watcher.Changed += OnChanged;
@@ -144,5 +145,4 @@ public async Task ExecuteAsync(Func<Cancel, Task> innerAction, Cancel cancellati
144145

145146
public void Dispose() => _semaphore.Dispose();
146147
}
147-
148148
}

0 commit comments

Comments
 (0)