Repository navigation
Add API property search with direct links to matching fields #4574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81c2d5f
34b7d57
f07d78b
07188e9
8fe995a
717693e
6940c51
3486146
486e2ab
8255e41
9d9630d
58a9630
e596b46
9f0a77f
e625b47
4544644
fc143a9
b5e5828
a215f39
6d8d93c
014bd99
79e01fa
467abf9
915d230
0e03da2
446b68b
23bdadf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using Elastic.ApiExplorer.Infrastructure; | ||
| using Elastic.Documentation.Search.Contract; | ||
|
|
||
| namespace Elastic.ApiExplorer.Components.PropertyTree; | ||
|
|
||
| internal static class ApiPropertyIndex | ||
| { | ||
| /// <param name="plainDescriptions">Plain text per description markdown, shared across a spec: shared schemas repeat the same text on every operation.</param> | ||
| public static IEnumerable<ApiPropertyEntry> Entries( | ||
| IEnumerable<ApiProperty> properties, | ||
| string location, | ||
| Dictionary<string, string> plainDescriptions | ||
| ) => | ||
| properties.Select( | ||
| property => new ApiPropertyEntry | ||
| { | ||
| Name = property.Name, | ||
| Path = string.IsNullOrEmpty(property.JsonPath) ? property.Name : property.JsonPath, | ||
| Type = property.Type.Text, | ||
| Location = location, | ||
| Anchor = property.AnchorId, | ||
| Description = PlainText(property.DescriptionMarkdown ?? "", plainDescriptions) | ||
| } | ||
| ); | ||
|
|
||
| private static string PlainText(string markdown, Dictionary<string, string> plainDescriptions) | ||
| { | ||
| if (!plainDescriptions.TryGetValue(markdown, out var text)) | ||
| plainDescriptions[markdown] = text = ApiMarkdown.StripHtml(ApiSeoDescription.ToPlainText(markdown)); | ||
| return text; | ||
| } | ||
|
|
||
| /// <summary>Every property in page order: each property, then its nested, dictionary and variant children.</summary> | ||
| public static IEnumerable<ApiProperty> Flatten(ApiPropertyList? properties) => | ||
| properties?.Items.SelectMany( | ||
| property => Flatten(property.Children.Properties) | ||
| .Concat(Flatten(property.Children.Dictionary?.Properties)) | ||
| .Concat(Flatten(property.Children.Variants)) | ||
| .Prepend(property) | ||
| ) | ||
| ?? []; | ||
|
|
||
| public static IEnumerable<ApiProperty> Flatten(ApiUnionVariants? variants) => | ||
| variants?.Variants.Where(v => v.ShowProperties && v.Properties is not null).SelectMany(v => Flatten(v.Properties)) ?? []; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Text.RegularExpressions; | ||
| using Elastic.ApiExplorer.Components.PropertyTree; | ||
| using Elastic.ApiExplorer.Infrastructure; | ||
| using Elastic.ApiExplorer.Model; | ||
| using Elastic.ApiExplorer.Operations; | ||
|
|
@@ -16,6 +17,7 @@ | |
| using Elastic.Documentation.Search; | ||
| using Elastic.Documentation.Search.Contract; | ||
| using Elastic.Documentation.Versions; | ||
| using Microsoft.AspNetCore.Html; | ||
| using Microsoft.OpenApi; | ||
| using Microsoft.OpenApi.Reader; | ||
|
|
||
|
|
@@ -66,6 +68,7 @@ public IEnumerable<DocumentationDocument> ConvertToDocuments(OpenApiDocument ope | |
| // All API products currently version against Stack | ||
| var currentStack = versionsConfiguration.GetVersioningSystem(VersioningSystemId.Stack).Current; | ||
|
|
||
| var plainDescriptions = new Dictionary<string, string>(); | ||
| foreach (var path in openApiDocument.Paths) | ||
| { | ||
| if (path.Value.Operations == null) | ||
|
|
@@ -117,6 +120,23 @@ public IEnumerable<DocumentationDocument> ConvertToDocuments(OpenApiDocument ope | |
| } | ||
|
|
||
| var body = bodyBuilder.ToString(); | ||
| var apiOperation = new ApiOperation(operation.Key, operation.Value, path.Key, path.Value, product); | ||
| var builder = new ApiPropertyTreeBuilder( | ||
| openApiDocument, | ||
| new PropertyDisplayOptions | ||
| { | ||
| // Listing identity keys on the markdown and the index stores plain text, so nothing here needs the HTML. | ||
| RenderMarkdown = _ => HtmlString.Empty, | ||
| ApiRootUrl = productUrl, | ||
| VersionsConfiguration = versionsConfiguration | ||
| } | ||
| ); | ||
| var endpoint = OperationEndpoint.Build(apiOperation, operation.Value.Description, []); | ||
| var trees = OperationPageModel.BuildPropertyTrees( | ||
| apiOperation, | ||
| new SchemaAnalyzer(openApiDocument), | ||
| new ParameterRowSource(builder, null, endpoint) | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Severity: P3 (Low) Pass the operation's supplemental documentation into property indexing instead of always supplying Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is substantial enough to track separately. Created #4662 as a follow-up. Not blocking this PR. |
||
|
|
||
| // Extract tags as headings | ||
| var headings = operation.Value.Tags?.Select(t => t.Name).Where(n => !string.IsNullOrEmpty(n)).OfType<string>().ToArray() | ||
|
|
@@ -143,6 +163,17 @@ public IEnumerable<DocumentationDocument> ConvertToDocuments(OpenApiDocument ope | |
| ], | ||
| Api = new ApiOperationMetadata | ||
| { | ||
| Properties = trees.IndexEntries(plainDescriptions), | ||
| Routes = endpoint | ||
| .Rows | ||
| .Select( | ||
|
Comment on lines
+167
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Severity: P2 (Medium) Populate Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is substantial enough to track separately. Created #4663 as a follow-up. Not blocking this PR. |
||
| row => new ApiRouteEntry | ||
| { | ||
| Path = row.Route, | ||
| Methods = [row.Method.ToUpperInvariant(), .. row.AlsoMethods.Select(m => m.ToUpperInvariant())] | ||
| } | ||
| ) | ||
| .ToArray(), | ||
| Endpoints = ApiEndpointPath.IndexKeys([path.Key, .. AlternatePaths(operation.Value.Description)]), | ||
| Method = method, | ||
| Path = path.Key, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using Elastic.ApiExplorer.Components.PropertyTree; | ||
| using Elastic.ApiExplorer.Model; | ||
| using Elastic.Documentation.Search.Contract; | ||
| using Microsoft.OpenApi; | ||
|
|
||
| namespace Elastic.ApiExplorer.Operations; | ||
|
|
||
| internal record OperationPropertyTrees( | ||
| ApiPropertyList Path, | ||
| ApiPropertyList Query, | ||
| ApiPropertyList Header, | ||
| IReadOnlyList<ApiMediaContent> Request, | ||
| IReadOnlyList<ApiResponse> Responses | ||
| ) | ||
| { | ||
| public ApiPropertyEntry[] IndexEntries(Dictionary<string, string> plainDescriptions) | ||
| { | ||
| IEnumerable<ApiPropertyEntry> Entries(IEnumerable<ApiProperty> rows, string location) => | ||
| ApiPropertyIndex.Entries(rows, location, plainDescriptions); | ||
|
|
||
| return [ | ||
| .. Entries(ApiPropertyIndex.Flatten(Path), "path"), | ||
| .. Entries(ApiPropertyIndex.Flatten(Query), "query"), | ||
| .. Entries(ApiPropertyIndex.Flatten(Header), "header"), | ||
| .. Entries(Request.SelectMany(Rows), "request"), | ||
| .. Entries(Responses.SelectMany(response => response.Contents).SelectMany(Rows), "response") | ||
| ]; | ||
| } | ||
|
|
||
| private static IEnumerable<ApiProperty> Rows(ApiMediaContent content) => | ||
| ApiPropertyIndex.Flatten(content.Properties).Concat(ApiPropertyIndex.Flatten(content.UnionVariants)); | ||
| } | ||
|
|
||
| public partial record OperationPageModel | ||
| { | ||
| internal static OperationPropertyTrees BuildPropertyTrees(ApiOperation operation, SchemaAnalyzer analyzer, ParameterRowSource source) | ||
| { | ||
| // Repeated shapes link to their first listing, so consumers must build in page order. | ||
| var path = BuildParameters(operation.Parameters, ParameterLocation.Path, source); | ||
| var query = BuildParameters(operation.Parameters, ParameterLocation.Query, source); | ||
| var header = BuildParameters(operation.Parameters, ParameterLocation.Header, source); | ||
| var request = BuildMediaContents( | ||
| operation.Operation.RequestBody?.Content, | ||
| new PropertyTreeScope | ||
| { | ||
| Prefix = "req", | ||
| JsonPath = "", | ||
| IsRequest = true, | ||
| DescriptionOverrides = source.Supplemental?.RequestBodyOverrides | ||
| }, | ||
| analyzer, | ||
| source.Builder | ||
| ); | ||
| return new OperationPropertyTrees(path, query, header, request, BuildResponses(operation.Operation, analyzer, source.Builder)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.