Skip to content

Read the OpenAPI version index through a domain model - #4899

Merged
Mpdreamz merged 5 commits into
mainfrom
split/14-version-index
Nov 27, 2026
Merged

Mpdreamz merged 5 commits into
mainfrom
split/14-version-index

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The API explorer now reads the OpenAPI version index into a VersionIndex record with named rules, and every rendered page, diagnostic and fetch stays the same.

Affects: Internals only

Stack: 14 of 16 in the split of #4530, on top of the foundation #4888.

Why

The version index is parsed straight into nested dictionaries and has no declared rules, so what makes an index valid is implicit in the client's lookups. #4530 introduces a domain record, a loader and named rules for each config file. This PR does that for the version index only, as a pure refactor.

What

Domain record and rules

VersionIndex, VersionIndexRepository, VersionIndexSpec and VersionMoniker in Elastic.Documentation.OpenApi keep every level in the order the index wrote it. VersionIndexConstraints holds two rules: a moniker is main or a major number (warning), and a key resolves to a version of its own major (error).

Loader and client

VersionIndexLoader in the API explorer declares one Loader.For over the existing JSON wire type. VersionIndexClient reads the response into text, loads it and looks monikers up on the record. Fetch errors, retry, the "declares no repositories" and "no entry for ..." messages keep their text. Configuration makes its internals visible to Elastic.ApiExplorer so the loader can use Loader.

Tests

Constraint tests (examples plus a property over valid indexes), loader tests, two client tests that pin the written moniker order and that a rule-breaking index reports nothing, and a property test that the publisher's VersionIndexBuilder output does not depend on key order.

Deferred behaviour changes

A JSON null inside the index keeps failing where it does today: the model keeps it as written, and a lookup that reaches it throws NullReferenceException, which OpenApiGenerator reports as "API '...' could not be generated". A null in an unrelated repository or spec has no effect. Two client tests pin this and pass unchanged against the base commit. Reporting a null as a parse error is deferred.

  • Reading monikers sorted (the index is read in written order today and stays so).
  • Reporting the index's rule violations (A8 warning, A13 error) as global warnings, once per index.
  • VersionIndexPublisher refusing to write an index that breaks a rule (keeps the openapi-index lambda free of the domain assembly).
  • The order-independence law as a rule on a key listing (VersionIndexOrderConstraints): rules cannot live next to the builder outside the domain, so it is a property test here.

Verify

mise run test
dotnet test --project tests/Elastic.ApiExplorer.Tests
dotnet test --project tests/Elastic.Documentation.OpenApiIndex.Tests
mise run snap:status

No verified snapshot changed.

🤖 Generated with Claude Code

Golden compare

Local builds of the isolated docs, the prod assembler site and the codex example site, this branch against the base commit a01a289a3 (aggregate counts; the output stays local).

Site Files Differing
Isolated docs 23,103 0
Assembler (prod) 57,053 0
Codex (example config) 23,248 4

The isolated build downloads live OpenAPI specs, so it is only comparable between captures taken back to back; these were. The codex build is nondeterministic on unchanged code: recaptures of the base commit differ from each other in codex/index.html and in one repository that has both x.md and x/index.md, which write the same output path.

Found by generated data

  • A null version of a recognized moniker made version-key-matches-version throw (found by review, kept fixed; pinned by ANullVersionOfARecognizedMoniker_IsAnErrorNotAThrow and covered by the hostile generator).
  • VersionIndex.Equals, GetHashCode and AllMonikers threw on a null Repositories list, which AutoTest's counter-example search builds. They now treat it as empty, like the inner records. The loader never produces it, so main's behaviour is unchanged (AnIndexWithNullRepositories_IsComparedAndWalkedAsAnEmptyOne).

The API explorer now loads index.json into a VersionIndex record that keeps today's key order, and the two rules about its monikers live in VersionIndexConstraints. Nothing the build reports or renders changes: the rules run in the loader and their findings are not surfaced yet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 17, 2026 17:23
@Mpdreamz Mpdreamz added the chore label Nov 17, 2026
@Mpdreamz
Mpdreamz requested a review from akira28 November 17, 2026 17:23
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4899/

The loader no longer turns a null anywhere in the index into a fetch error. The model keeps the null as written, so only a lookup that reaches it throws, and OpenApiGenerator reports that exception as before. Client tests pin both cases against the old behaviour.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A JSON "version": null under a numeric moniker made the key-matches-version
rule throw a NullReferenceException. Main resolves such an entry with a null
version, so the rule now skips it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A null version under main or a numeric moniker still resolves on main, so the
client keeps working; the model now says what is wrong with it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AutoTest runs every rule over generated legal indexes and proves each rule can fire. A second generator adds blank, case-variant, numeric-looking and null values and checks that no rule throws. AutoTest's counter-example search found that a null Repositories list made Equals, GetHashCode and AllMonikers throw, so they now treat it as empty like the inner records.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz
Mpdreamz merged commit e962976 into main Nov 27, 2026
44 checks passed
@Mpdreamz
Mpdreamz deleted the split/14-version-index branch November 27, 2026 11:23
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