Merge API explorer improvements#3523
Conversation
* 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>
|
Label error. Requires exactly 1 of: automation, breaking, bug, changelog:skip, chore, ci, dependencies, documentation, enhancement, feature, fix, redesign. Found: |
📝 WalkthroughWalkthroughThe PR extends the API Explorer with three main features: tag landing pages, per-operation code examples, and prerequisites rendering. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (24)
docs/_docset.ymldocs/configure/content-set/api-explorer.mddocs/elasticsearch-openapi-docs.jsondocs/elasticsearch-openapi.jsondocs/kibana-openapi.jsonsrc/Elastic.ApiExplorer/ApiCodeBlockModel.cssrc/Elastic.ApiExplorer/ApiRenderContext.cssrc/Elastic.ApiExplorer/ApiViewModel.cssrc/Elastic.ApiExplorer/Landing/LandingNavigationItem.cssrc/Elastic.ApiExplorer/Landing/LandingView.cshtmlsrc/Elastic.ApiExplorer/Landing/TagLandingView.cshtmlsrc/Elastic.ApiExplorer/Landing/TagLandingViewModel.cssrc/Elastic.ApiExplorer/OpenApiGenerator.cssrc/Elastic.ApiExplorer/Operations/OpenApiXReqAuthParser.cssrc/Elastic.ApiExplorer/Operations/OperationView.cshtmlsrc/Elastic.ApiExplorer/Operations/OperationViewModel.cssrc/Elastic.ApiExplorer/Schemas/SchemaView.cshtmlsrc/Elastic.ApiExplorer/Shared/_ApiCodeBlock.cshtmltests/Elastic.ApiExplorer.Tests/CodeSampleTests.cstests/Elastic.ApiExplorer.Tests/Elastic.ApiExplorer.Tests.csprojtests/Elastic.ApiExplorer.Tests/TagMetadataTests.cstests/Elastic.ApiExplorer.Tests/TestData/elasticsearch-x-req-auth-cat-indices-sample.jsontests/Elastic.ApiExplorer.Tests/TestData/kibana-openapi-no-x-req-auth-sample.jsontests/Elastic.ApiExplorer.Tests/XReqAuthTests.cs
| [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"); | ||
| } |
There was a problem hiding this comment.
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.
This PR merges the branch that @szabosteve and I worked on last month. In particular, it includes the following improvements: