Skip to content

[API Explorer] Add support for x-req-auth#3168

Merged
lcawl merged 2 commits into
api-explorer-improvementsfrom
api-explorer-x-req
Apr 22, 2026
Merged

[API Explorer] Add support for x-req-auth#3168
lcawl merged 2 commits into
api-explorer-improvementsfrom
api-explorer-x-req

Conversation

@lcawl
Copy link
Copy Markdown
Contributor

@lcawl lcawl commented Apr 22, 2026

Summary

Adds support for the OpenAPI operation extension x-req-auth in the API Explorer.
Render the information in a Prerequisites block on each operation page.

NOTE: x-req-auth is implemented in the Elasticsearch specification in elastic/elasticsearch-specification#6007

Screenshots

image

Implementation

  • OpenApiXReqAuthParser: Reads x-req-auth as a JSON array of strings on the operation. Trims each line; non-string JSON values are stringified. Returns null if the key is missing, not an array, or all entries are empty—so the UI stays hidden. Logs warnings (when a logger is available) for unexpected shapes or parse issues.
  • ApiRenderContext: New optional ApiExplorerLog (ILogger?) for extension parsing.
  • OpenApiGenerator: Wires ApiExplorerLog = _logger when constructing ApiRenderContext for API product generation.
  • ApiViewModel: Exposes protected ApiRenderContext RenderContext so operation code can use the model and optional logger.
  • OperationViewModel:
    • RequiredAuthItems from the parser.
    • GetTocItems: Inserts Prerequisites (anchor prerequisites) after Paths when there is at least one line; coexists with existing Code Examples / x-codeSamples TOC behavior.
  • OperationView.cshtml: Renders the Prerequisites section (same general styling as other primary operation sections).

Tests

  • XReqAuthTests: Parser coverage (minimal spec, empty array, Elasticsearch- and Kibana-style TestData JSON fixtures—no dependency on the full repo elasticsearch-openapi.json / kibana-openapi.json).
  • Test project copies TestData/**/*.json to output.

Documentation

  • docs/configure/content-set/api-explorer.md: Documents x-req-auth under OpenAPI extensions (format, behavior, TOC placement, when the section is omitted, warnings), and lists it in the extensions overview.

I've done some minor cleanup in that page as well (re-ordering the sections under "OpenAPI extensions".

Generative AI disclosure

  1. Did you use a generative AI (GenAI) tool to assist in creating this contribution?
  • Yes
  • No
  1. If you answered "Yes" to the previous question, please specify the tool(s) and model(s) used (e.g., Google Gemini, OpenAI ChatGPT-4, etc.).

Tool(s) and model(s) used: composer-2

@lcawl lcawl marked this pull request as ready for review April 22, 2026 20:03
@lcawl lcawl requested review from a team as code owners April 22, 2026 20:03
@lcawl lcawl requested a review from cotti April 22, 2026 20:03
@lcawl lcawl merged commit 9fdf279 into api-explorer-improvements Apr 22, 2026
23 of 24 checks passed
@lcawl lcawl deleted the api-explorer-x-req branch April 22, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants