Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
<PackageVersion Include="Elastic.Transport.VirtualizedCluster" Version="1.1.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="11.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="11.0.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="3.11.0" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.31" />
<PackageVersion Include="Microsoft.OpenApi" Version="3.11.1" />
<PackageVersion Include="Tomlyn" Version="2.11.1" />
<PackageVersion Include="TUnit" Version="1.85.0" />
<!-- The TUnit package pulls these in. Test projects exclude their assets: nothing here uses code coverage or sends test telemetry,
Expand Down
4 changes: 2 additions & 2 deletions docs/data/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ navigation_title: REST API

{{dbuild}} includes a REST API server (`Elastic.Documentation.Api`) that powers search, AI assistance, and content change feeds for the documentation site.

The server describes itself in an OpenAPI document at `/docs/_api/v1/openapi.json`, generated from its endpoints. It lists every endpoint with its parameters, request bodies, responses, and error codes. Requests through `www.elastic.co` need the cookie `feature_search_or_askai_enabled=true`; without it, the CDN answers `403`.
The server describes itself in an OpenAPI document at `/docs/_api/v1/openapi.json`, generated from its endpoints. It lists every endpoint with its parameters, request bodies, responses, and error codes.

## Endpoints

Expand Down Expand Up @@ -88,7 +88,7 @@ Every error is an [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem, se
- `detail` explains this occurrence, for people.
- `traceId` names the request's trace. Quote it when you report a problem.

Errors from the CDN, such as the `403` for a missing cookie, aren't problems and aren't JSON.
Errors from the CDN, such as a `403` from its firewall, aren't problems and aren't JSON.

### Invalid arguments [invalid-arguments]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,19 @@ IReadOnlyList<CodeSample> codeSamples
for (var i = 0; i < scenarios.Count; i++)
scenarios[i] = scenarios[i] with { Responses = MergeSharedResponses(scenarios[i].Responses, sharedResponses) };
}
// Response-only examples are one example, unless samples name several of them: those samples are the requests
// that tell the examples apart, as on a GET with one sample per example. Unnamed ones (error statuses) are shared.
else if (!hasRequestScenarios && scenarios.Count > 1)
scenarios = CollapseIntoSingleScenario(scenarios);
{
var named = scenarios.Where(s => NamedBySample(s, codeSamples)).ToList();
if (named.Count > 1)
{
var shared = scenarios.Except(named).SelectMany(s => s.Responses).SelectMany(r => r.Examples).ToList();
scenarios = [.. named.Select(s => s with { Responses = MergeSharedResponses(s.Responses, shared) })];
}
else
scenarios = CollapseIntoSingleScenario(scenarios);
}

// Samples that name an example, by language suffix (cURL_tag_names) or by title, belong to that example.
var tied = codeSamples.Where(static c => c.IsTied).ToArray();
Expand Down Expand Up @@ -269,6 +280,9 @@ IReadOnlyList<ExampleDisplay> shared
return merged;
}

private static bool NamedBySample(ExampleScenario scenario, IReadOnlyList<CodeSample> codeSamples) =>
codeSamples.Any(sample => string.Equals(sample.ExampleTitle, scenario.Title, StringComparison.OrdinalIgnoreCase));

/// <summary>
/// Response-only operations often name each status differently; fold them into one
/// scenario so the rail exposes status tabs instead of a scenario <c>select</c>.
Expand Down
3 changes: 3 additions & 0 deletions src/api/Elastic.Documentation.Api/ApiProblems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static class ApiProblems
[FeedbackUnavailable] = "Feedback unavailable"
};

/// <summary>The fixed title of a problem type, such as <see cref="InvalidArguments"/>.</summary>
public static string TitleOf(string type) => Titles[type];

/// <summary>The absolute <c>type</c> URI of a problem type, such as <see cref="InvalidArguments"/>.</summary>
public static string TypeUri(string type) => TypeBase + type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace Elastic.Documentation.Api.AskAi;
/// Request model for submitting feedback on a specific Ask AI message.
/// Using Guid type ensures automatic validation during JSON deserialization.
/// </summary>
/// <param name="MessageId">The id of the answer, from its stream events.</param>
/// <param name="ConversationId">The id of the conversation, from its <c>conversation_start</c> event.</param>
/// <param name="Reaction">Whether the answer helped.</param>
public record AskAiMessageFeedbackRequest(Guid MessageId, Guid ConversationId, Reaction Reaction);

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/api/Elastic.Documentation.Api/AskAi/IAskAiGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Elastic.Documentation.Api.AskAi;
/// </param>
public record AskAiGatewayResponse(Stream Stream, Guid? GeneratedConversationId);

/// <summary>A question for Ask AI.</summary>
/// <param name="Message">The question, in plain language.</param>
/// <param name="ConversationId">The conversation to continue, from an earlier <c>conversation_start</c> event; null starts a new one.</param>
public record AskAiRequest(string Message, Guid? ConversationId);

public interface IAskAiService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- The OpenAPI document reads its descriptions from these doc comments; not every member has one yet. -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -32,6 +35,10 @@
<PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
</ItemGroup>
<ItemGroup>
<!-- Response examples of the OpenAPI document; ApiExamples reads them by file name. -->
<EmbeddedResource Include="OpenApi\Examples\*.json" LogicalName="openapi-examples/%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Elastic.Documentation.Api.Tests</_Parameter1>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Elastic.Documentation.Api/MappingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Cancel ctx
.WithTags(AskAiTag)
.WithName("ask-ai-stream")
.WithSummary("Stream an Ask AI answer as server-sent events")
.Produces(StatusCodes.Status200OK, contentType: "text/event-stream")
.Produces<string>(StatusCodes.Status200OK, "text/event-stream")
.ProducesErrors(StatusCodes.Status400BadRequest);

// UUID validation is automatic via Guid type deserialization (returns 400 if invalid)
Expand Down
Loading
Loading