Skip to content

Describe the docs API's OpenAPI document and add examples and code samples - #4942

Merged
akira28 merged 3 commits into
mainfrom
feature/docs-api-openapi-examples
Nov 18, 2026
Merged

akira28 merged 3 commits into
mainfrom
feature/docs-api-openapi-examples

Conversation

@akira28

@akira28 akira28 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The docs API's OpenAPI document (/docs/_api/v1/openapi.json) now explains itself. Every operation, parameter, response, tag, schema and field has a description, and every field and parameter has an example. Each operation also has example requests with real responses, and x-codeSamples with a curl command and, where one is released, the Elastic CLI command.

Affects: API

Prompt summary: Add examples and x-codeSamples to the docs API's OpenAPI document, with summaries and descriptions for operations and every field, and an example for every field. Update the OpenAPI packages.

Why

The document from #4896 listed routes and types but explained nothing: no operation, parameter or field had a description, and there were no examples. API Explorer synthesizes a Console and curl sample when an operation has none, but Console is Kibana's Dev Tools and can't call this API.

What

Examples and code samples (OpenApi/ApiExamples.cs)

  • Example requests: each operation has one or more, such as a search, an endpoint lookup with view=full, and a group listing for GET /apis/{api}/operations.
  • Response examples: real replies captured from edge and trimmed, kept as JSON files in OpenApi/Examples and embedded in the assembly.
    • The Ask AI stream example is built from the real event records and their JSON context, so it can't drift from what the API sends.
    • Every error response gets an RFC 9457 problem example, with the type and detail that operation really returns, such as operation-not-found on get-api-operation and feedback-unavailable on the feedback endpoints.
  • x-codeSamples: a curl command per example request, labeled with the example's title so API Explorer ties them together. search and ask-ai-stream also get the released Elastic CLI command (elastic docs search, elastic docs ask). elastic docs api waits for feat(docs): add elastic docs api commands cli#825.
  • Parameter examples: each parameter takes its value from the operation's first example request. Parameters no example request sets get one from a table.
  • Fix: the Ask AI stream response now declares text/event-stream content. It was missing from the document.

API Explorer: response-only examples stay apart

A GET has no request body examples, so API Explorer folded all its response examples into one scenario: the three list-api-operations examples all showed the search response. Now, when x-codeSamples name several response-only examples, each one keeps its own response, and the unnamed ones (error statuses) are shared as status tabs. Operations whose samples name no example behave as before (OperationPageModel.Examples.cs).

No more cookie gate (folds in #4898)

elastic/docs-infra#523 drops production's feature_search_or_askai_enabled cookie gate on the docs API. The curl samples send no cookie, the OpenAPI description no longer mentions one, and docs/data/api.md drops the cookie sentence. Tests check that neither the description nor any curl sample names a cookie.

Descriptions

  • Operations, parameters, responses and tags (OpenApi/ApiDescriptions.cs): the endpoints are lambdas, so this text lives in transformers, in one file.
    • Responses get descriptions instead of OK or Bad Request.
    • The tag descriptions note, for example, that page feedback needs a WAF token, and that every operation lookup names its API.
  • Fields: doc comments on the response and request types. The API, search and search contract projects now generate XML documentation (with CS1591 off), and Microsoft.AspNetCore.OpenApi's source generator turns <summary> into description and <example> into examples. Writing the comments also documents those types in code.
    • Every scalar field has a real example, mostly harvested from the response examples.
    • Positional records and ASP.NET's ProblemDetails can't carry per-property comments, so a schema transformer sets theirs.
  • Broken links: turning on XML docs in the contract project surfaced four broken crefs in existing comments. They are now plain code text.

Packages

  • Microsoft.OpenApi 3.11.0 → 3.11.1 (bug fixes only: extension preservation in copy constructors, external refs, reader allocations).
    • This bypasses the 14-day NuGet cooldown in dependabot.yml: 3.11.1 was published on 2026-11-16, and the bump was explicitly requested.
    • API Explorer's tests pass on it.
  • Microsoft.AspNetCore.OpenApi is already on the latest, 11.0.0.
  • The Microsoft.OpenApi.Readers 1.6.31 pin is removed. No project references it; its readers are part of Microsoft.OpenApi since 2.0.

Verify

dotnet test --project tests/Elastic.Documentation.Api.Tests
# OpenApiExamplesTests: every response example reads as its type with unknown members disallowed, request bodies as
#   their request records, stream events as AskAiEvent; every curl targets its operation's route; problems carry our types
# OpenApiDescriptionsTests: everything is described, and every field and parameter has an example
dotnet test --project tests/Elastic.ApiExplorer.Tests   # 1559 pass on Microsoft.OpenApi 3.11.1, with ExampleScenarioTests for the pairing
dotnet publish src/api/Elastic.Documentation.Api -c Release -r osx-arm64

Locally: 319 API, 76 MCP and 1559 API Explorer tests pass, and the solution builds. The AOT publish has no warnings. The native binary serves the document with its examples, x-codeSamples and descriptions. Rendered with a temporary docset entry, the list-api-operations page shows each example with its own response (totalHits 9, 1 and 1), each with the 400, 404 and 503 tabs.

Merge after elastic/docs-infra#523 is applied: until then, production answers 403 to uncached requests without the cookie.

Follow-up: #4897's copy of the document (docs/docs-api.json) predates this PR. Regenerate it after this merges.

🤖 Generated with Claude Code

…mples

Every operation, parameter, response, tag, schema and field has a
description, and every field and parameter an example. Each operation has
example requests with real responses, a curl sample per example, and the
Elastic CLI command where one is released. Response examples are trimmed
replies from the API, checked against the response types. The Ask AI stream
response now declares its text/event-stream content.

Field descriptions and examples come from doc comments, so the API, search and
search contract projects generate XML documentation. Microsoft.OpenApi moves
to 3.11.1, and the unused Microsoft.OpenApi.Readers pin is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 requested a review from a team as a code owner November 18, 2026 10:59
@akira28
akira28 requested a review from technige November 18, 2026 10:59
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

…type

- API Explorer keeps response-only examples apart when samples name them, sharing the unnamed error statuses as tabs instead of folding all into one example.
- Error examples show the problem type each operation really returns.
- curl samples send the cookie www.elastic.co's CDN still requires until elastic/docs-infra#523 is applied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
elastic/docs-infra#523 drops production's cookie gate on the docs API, so the curl samples, the OpenAPI description and docs/data/api.md stop asking for feature_search_or_askai_enabled. Folds in #4898.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 merged commit 2884fa6 into main Nov 18, 2026
44 checks passed
@akira28
akira28 deleted the feature/docs-api-openapi-examples branch November 18, 2026 11:54
akira28 added a commit that referenced this pull request Nov 18, 2026
…riptions

Picks up #4942: every operation, parameter and field described, example requests with real responses, and curl samples without the retired cookie.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant