Skip to content

Commit 64f9b31

Browse files
committed
start building out api pages
1 parent 2d906f5 commit 64f9b31

File tree

9 files changed

+182
-17
lines changed

9 files changed

+182
-17
lines changed

src/Elastic.ApiExplorer/Elastic.ApiExplorer.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<InvariantGlobalization>true</InvariantGlobalization>
8+
<PublishAot>true</PublishAot>
9+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
10+
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
11+
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
12+
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
713
</PropertyGroup>
814

915
<ItemGroup>

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@using Elastic.ApiExplorer.Landing
2+
@using Elastic.ApiExplorer.Operations
23
@using Elastic.Documentation.Configuration.Assembler
34
@using Elastic.Documentation.Configuration.Builder
5+
@using Microsoft.OpenApi.Models
46
@inherits RazorSliceHttpResult<Elastic.ApiExplorer.Operations.OperationViewModel>
57
@implements IUsesLayout<Elastic.ApiExplorer._Layout, GlobalLayoutViewModel>
68
@functions {
@@ -23,21 +25,70 @@
2325
}
2426
@{
2527
var parent = Model.CurrentNavigationItem.Parent as EndpointNavigationItem;
28+
var self = Model.CurrentNavigationItem as OperationNavigationItem;
29+
var allOperations =
30+
parent is not null && parent.NavigationItems.Count > 0 && parent.NavigationItems.All(n => n.Hidden)
31+
? parent.NavigationItems
32+
: self is not null
33+
? [self]
34+
: [];
35+
36+
var operation = Model.Operation.Operation;
2637
}
27-
@if (parent is not null && parent.NavigationItems.Count > 0 && parent.NavigationItems.All(n => n.Hidden))
28-
{
29-
<ul>
30-
@foreach (var overload in parent.NavigationItems)
38+
39+
<div class="w-full h-full grid
40+
grid-cols-1
41+
md:grid-cols-[1fr_var(--max-examples-width)]
42+
lg:grid-cols-[1fr_var(--max-examples-width)]
43+
">
44+
<section id="elastic-api-v3">
45+
<h1>@operation.Summary</h1>
46+
<p>
47+
@operation.Description
48+
</p>
49+
<ul class="api-url-listing">
50+
@foreach (var overload in allOperations)
51+
{
52+
var method = overload.Model.OperationType.ToString().ToLowerInvariant();
53+
var current = overload.Model.Route == Model.Operation.Route && overload.Model.OperationType == Model.Operation.OperationType ? "current" : "";
54+
<li class="api-url-list-item">
55+
<a href="@overload.Url" class="@current">
56+
<span class="api-method api-method-@method">@method.ToUpperInvariant()</span>
57+
<span class="api-url">@overload.Model.Route</span>
58+
</a>
59+
</li>
60+
}
61+
</ul>
62+
@{
63+
var pathParameters = operation.Parameters?.Where(p => p.In == ParameterLocation.Path).ToArray() ?? [];
64+
}
65+
@if (pathParameters.Length > 0)
3166
{
32-
<li>
33-
<a href="@overload.Url">@overload.Model.OperationType @overload.Model.Route</a>
34-
</li>
67+
<h3>Path Parameters</h3>
68+
<dl>
69+
@foreach (var path in pathParameters)
70+
{
71+
<dt id="@path.Name"><a href="#@path.Name"><code>@path.Name</code></a></dt>
72+
<dd>@path.Description</dd>
73+
}
74+
</dl>
75+
}
76+
@{
77+
var queryStringParameters = operation.Parameters?.Where(p => p.In == ParameterLocation.Query).ToArray() ?? [];
78+
}
79+
@if (queryStringParameters.Length > 0)
80+
{
81+
<h3>Query String Parameters</h3>
82+
<dl>
83+
@foreach (var path in queryStringParameters)
84+
{
85+
<dt id="@path.Name"><a href="#@path.Name"><code>@path.Name</code></a></dt>
86+
<dd>@path.Description</dd>
87+
}
88+
</dl>
3589
}
36-
</ul>
37-
}
38-
39-
<section id="elastic-docs-v3">
40-
<h1>Id: @Model.Operation.Operation.OperationId</h1>
41-
<h2>Name: @Model.Operation.ApiName</h2>
42-
<h2>Url: @Model.Operation.OperationType.ToString() @Model.Operation.Route</h2>
4390
</section>
91+
<aside>
92+
93+
</aside>
94+
</div>

src/Elastic.ApiExplorer/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
}
66
<div class="w-full h-full grid
77
grid-cols-1
8-
md:grid-cols-[var(--max-sidebar-width)_1fr]
9-
lg:grid-cols-[var(--max-sidebar-width)_1fr]
8+
md:grid-cols-[var(--max-api-sidebar-width)_1fr]
9+
lg:grid-cols-[var(--max-api-sidebar-width)_1fr]
1010
">
1111
@await RenderPartialAsync(_PagesNav.Create(Model))
1212
<div class="justify-center px-6 lg:px-0">
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
.api-url-listing {
3+
@apply mt-4;
4+
margin-left: 0 !important;
5+
&:has(.api-method-get) {
6+
.api-method {
7+
width: calc(4ch + var(--spacing));
8+
}
9+
}
10+
&:has(.api-method-put) {
11+
.api-method {
12+
width: calc(4ch + var(--spacing));
13+
}
14+
}
15+
&:has(.api-method-head) {
16+
.api-method {
17+
width: calc(5ch + var(--spacing));
18+
}
19+
}
20+
&:has(.api-method-post) {
21+
.api-method {
22+
width: calc(5ch + var(--spacing));
23+
}
24+
}
25+
&:has(.api-method-delete) {
26+
.api-method {
27+
width: calc(7ch + var(--spacing));
28+
}
29+
}
30+
31+
li {
32+
list-style-type: none;
33+
margin-left: 0;
34+
a {
35+
@apply no-underline w-full p-4 pl-4 pr-4 inline-block text-grey-80;
36+
@apply border rounded-sm border-grey-20 bg-grey-10;
37+
}
38+
a.current {
39+
@apply border-grey-30 bg-white p-4 text-grey-120;
40+
font-weight: bold;
41+
}
42+
a:hover {
43+
@apply border-grey-30 bg-white text-grey-120;
44+
font-weight: bold;
45+
}
46+
}
47+
li:only-child {
48+
a.current {
49+
@apply border rounded-sm border-grey-20 bg-white;
50+
}
51+
a.current:hover {
52+
@apply border-grey-20 bg-white;
53+
}
54+
55+
}
56+
.api-method {
57+
@apply border rounded-sm;
58+
padding-left: var(--spacing);
59+
padding-right: var(--spacing);
60+
font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
61+
font-feature-settings: var(--default-mono-font-feature-settings, normal);
62+
font-variation-settings: var(--default-mono-font-variation-settings, normal);
63+
font-size: 0.8em;
64+
display: inline-block;
65+
font-weight: bold;
66+
}
67+
.api-method-get {
68+
@apply border-blue-elastic-30 bg-blue-elastic-10 text-blue-elastic;
69+
}
70+
.api-method-put {
71+
@apply border-yellow-30 bg-yellow-10 text-yellow-90;
72+
}
73+
.api-method-post {
74+
@apply border-green-30 bg-green-10 text-green-90;
75+
}
76+
.api-method-delete {
77+
@apply border-red-30 bg-red-10 text-red-90;
78+
}
79+
.api-url {
80+
margin-left: calc(var(--spacing) * 2);
81+
display: inline-block;
82+
}
83+
.api-url-list-item
84+
{
85+
@apply mt-4;
86+
}
87+
}
88+
#elastic-api-v3 {
89+
dt a {
90+
@apply no-underline;
91+
code {
92+
@apply p-1 inline-block;
93+
}
94+
}
95+
h1 {
96+
@apply pt-4;
97+
}
98+
h3 {
99+
@apply border-b-grey-20 border-b-1 pb-2;
100+
}
101+
}

src/Elastic.Documentation.Site/Assets/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@import './modal.css';
1717
@import './archive.css';
1818
@import './markdown/stepper.css';
19+
@import './api-docs.css';
1920

2021
:root {
2122
--outline-size: max(2px, 0.08em);
@@ -33,6 +34,9 @@
3334
var(--max-text-width) + (var(--max-sidebar-width) * 2) +
3435
calc(var(--content-spacing) * 2)
3536
);
37+
38+
--max-api-sidebar-width: calc(var(--spacing) * 70);
39+
--max-examples-width: calc(var(--max-api-sidebar-width) * 2);
3640
}
3741

3842
@media screen and (min-width: 767px) {

src/Elastic.Documentation.Site/Elastic.Documentation.Site.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
1010
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
1111
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
12-
1312
<IsPublishable>true</IsPublishable>
13+
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

src/Elastic.Documentation.Site/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
content: [
33
'./**/*.{html,js,cshtml}',
44
'../Elastic.Markdown/**/*.{html,js,cshtml}',
5+
'../Elastic.ApiExplorer/**/*.{html,js,cshtml}',
56
],
67
}

src/Elastic.Markdown/Elastic.Markdown.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<IsPublishable>true</IsPublishable>
1414
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
15+
<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
1516
</PropertyGroup>
1617

1718
<ItemGroup>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ private async Task<IResult> ServeApiFile(ReloadableGeneratorState holder, string
168168
var info = _writeFileSystem.FileInfo.New(path);
169169
if (info.Exists)
170170
{
171+
//TODO STREAM
171172
var contents = await _writeFileSystem.File.ReadAllTextAsync(info.FullName, ctx);
172173
return Results.Content(contents, "text/html");
173174
}

0 commit comments

Comments
 (0)