Skip to content

Merge API explorer improvements#3523

Open
lcawl wants to merge 6 commits into
mainfrom
api-explorer-improvements
Open

Merge API explorer improvements#3523
lcawl wants to merge 6 commits into
mainfrom
api-explorer-improvements

Conversation

@lcawl

@lcawl lcawl commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

lcawl and others added 6 commits June 17, 2026 08:36
* Add multi-language code sample tabs to API Explorer request examples

Parse x-codeSamples from OpenAPI operations and render them as
language-selectable tabs (Console, cURL, Python, JS, Ruby, PHP, Java)
inline within the Request Examples section, replacing the JSON code block.
Uses the existing tabs CSS/JS infrastructure with synced language
selection across operations via sessionStorage.

Made-with: Cursor

* Fix Elastic.ApiExplorer.Tests

* Render code examples as standalone section for all HTTP methods

The inline approach only worked for operations with request bodies
(PUT/POST/PATCH). GET/DELETE operations had x-codeSamples in the
spec but no Request Examples section to host them. Move language
tabs to a standalone Code Examples section that renders for every
operation with x-codeSamples, regardless of HTTP method. Restore
original Request Examples rendering unchanged.

Made-with: Cursor

* Hide Request Examples when single example duplicates Code Examples

When an operation has exactly one request example and x-codeSamples
are present, the request example is redundant (same content shown
in richer form via language tabs). Skip rendering it to avoid
duplication.

Made-with: Cursor

---------

Co-authored-by: lcawl <lcawley@elastic.co>
@github-actions

Copy link
Copy Markdown

Label error. Requires exactly 1 of: automation, breaking, bug, changelog:skip, chore, ci, dependencies, documentation, enhancement, feature, fix, redesign. Found:

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR extends the API Explorer with three main features: tag landing pages, per-operation code examples, and prerequisites rendering. ApiTag gains ExternalDocs and TagUrlSegment fields; OpenApiGenerator now parses tag metadata, computes URL segments via GenerateTagMoniker/BuildTagMonikerMap (with collision detection), and renders TagLandingView for each tag. Navigation URL resolution is refactored so ClassificationNavigationItem points to the root API index and TagNavigationItem computes /api/{suffix}/tags/{segment}/ URLs. A new OpenApiXReqAuthParser reads x-req-auth arrays into prerequisite lines; OperationViewModel gains CodeSamples from x-codeSamples with Console-first ordering. A shared _ApiCodeBlock partial replaces inline <pre><code> blocks throughout. The docset config switches to elasticsearch-openapi-docs.json.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Merge API explorer improvements' is vague and does not clearly summarize the main changes in the PR. Use a more specific title that highlights key improvements, such as 'Add tag landing pages, code samples, and authentication requirements to API Explorer'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description provides context by referencing six related pull requests and mentions key improvements (code samples, authentication, tag landing pages), which is related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch api-explorer-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Elastic.ApiExplorer.Tests/CodeSampleTests.cs`:
- Around line 66-83: The test assertions in
CodeSamples_PreservesOrderForNonConsole are too strict and will flap because the
ParseCodeSamples method uses a comparer that returns 0 for every non-Console
pair, making their order non-deterministic. Relax the assertions to only verify
that Console appears first in the result array
(result[0].Language.Should().Be("Console")), then use a more flexible assertion
approach like verifying the remaining languages are present but without
enforcing a specific order (using Contains or similar), rather than asserting
exact index positions for Python, curl, and Ruby samples.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1ce59feb-9388-4e27-a2e2-64a1aa7ee157

📥 Commits

Reviewing files that changed from the base of the PR and between b9bf134 and 757b253.

📒 Files selected for processing (24)
  • docs/_docset.yml
  • docs/configure/content-set/api-explorer.md
  • docs/elasticsearch-openapi-docs.json
  • docs/elasticsearch-openapi.json
  • docs/kibana-openapi.json
  • src/Elastic.ApiExplorer/ApiCodeBlockModel.cs
  • src/Elastic.ApiExplorer/ApiRenderContext.cs
  • src/Elastic.ApiExplorer/ApiViewModel.cs
  • src/Elastic.ApiExplorer/Landing/LandingNavigationItem.cs
  • src/Elastic.ApiExplorer/Landing/LandingView.cshtml
  • src/Elastic.ApiExplorer/Landing/TagLandingView.cshtml
  • src/Elastic.ApiExplorer/Landing/TagLandingViewModel.cs
  • src/Elastic.ApiExplorer/OpenApiGenerator.cs
  • src/Elastic.ApiExplorer/Operations/OpenApiXReqAuthParser.cs
  • src/Elastic.ApiExplorer/Operations/OperationView.cshtml
  • src/Elastic.ApiExplorer/Operations/OperationViewModel.cs
  • src/Elastic.ApiExplorer/Schemas/SchemaView.cshtml
  • src/Elastic.ApiExplorer/Shared/_ApiCodeBlock.cshtml
  • tests/Elastic.ApiExplorer.Tests/CodeSampleTests.cs
  • tests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csproj
  • tests/Elastic.ApiExplorer.Tests/TagMetadataTests.cs
  • tests/Elastic.ApiExplorer.Tests/TestData/elasticsearch-x-req-auth-cat-indices-sample.json
  • tests/Elastic.ApiExplorer.Tests/TestData/kibana-openapi-no-x-req-auth-sample.json
  • tests/Elastic.ApiExplorer.Tests/XReqAuthTests.cs

Comment on lines +66 to +83
[Fact]
public void CodeSamples_PreservesOrderForNonConsole()
{
var samples = new JsonArray(
new JsonObject { ["lang"] = "Python", ["source"] = "resp = client.search()" },
new JsonObject { ["lang"] = "curl", ["source"] = "curl -X GET ..." },
new JsonObject { ["lang"] = "Console", ["source"] = "GET /_search" },
new JsonObject { ["lang"] = "Ruby", ["source"] = "response = client.search" }
);
var operation = CreateOperationWithCodeSamples(samples);

var result = OperationViewModel.ParseCodeSamples(operation);

result[0].Language.Should().Be("Console");
result[1].Language.Should().Be("Python");
result[2].Language.Should().Be("curl");
result[3].Language.Should().Be("Ruby");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Don't assert exact order for non-Console samples.

ParseCodeSamples uses List.Sort with a comparer that returns 0 for every non-Console pair, so the Python/curl/Ruby order is not guaranteed. This can flap; either make the parser's ordering stable or relax this assertion to only pin the Console-first behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Elastic.ApiExplorer.Tests/CodeSampleTests.cs` around lines 66 - 83, The
test assertions in CodeSamples_PreservesOrderForNonConsole are too strict and
will flap because the ParseCodeSamples method uses a comparer that returns 0 for
every non-Console pair, making their order non-deterministic. Relax the
assertions to only verify that Console appears first in the result array
(result[0].Language.Should().Be("Console")), then use a more flexible assertion
approach like verifying the remaining languages are present but without
enforcing a specific order (using Contains or similar), rather than asserting
exact index positions for Python, curl, and Ruby samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants