Skip to content

[Lens] Improve Visualizations API documentation#259842

Closed
florent-leborgne wants to merge 37 commits into
mainfrom
lens-api-docs
Closed

[Lens] Improve Visualizations API documentation#259842
florent-leborgne wants to merge 37 commits into
mainfrom
lens-api-docs

Conversation

@florent-leborgne
Copy link
Copy Markdown
Member

@florent-leborgne florent-leborgne commented Mar 26, 2026

Closes #236265

Summary

Improve the Visualizations API documentation ahead of its public release in 9.4. This PR (Kibana) and a companion docs-content PR work together to create a cohesive documentation experience across the API reference and the narrative chart documentation.

Related: #260969 (Dashboards API docs, same pattern)

Documentation strategy

Users discovering the Visualizations API will follow one of three paths. Our changes ensure each path leads to success:

Path 1: Start from the API reference
A user lands on the API docs and wants to create a visualization. The tag intro orients them: what chart types exist, how data sources work (DSL vs ES|QL), and what the current limitations are. They pick an endpoint, see a concise description, copy a code sample, and it works out of the box with sample data. If they need a more complex example, the chart types table links directly to tested payload examples on each chart page.

Path 2: Start from the chart documentation
A user is reading about how to build a bar chart or a metric in the UI. At the bottom of each example and advanced scenario, a collapsible dropdown shows the equivalent API payload. They can copy it, modify it, and use it in their automation. The dropdown links back to the API reference for the full schema.

Path 3: Explore the schema
A user browses the request body schema to understand all available options. Every parameter they encounter has a clear, actionable description explaining what it does, its valid values, defaults, and relationships to other fields.

Changes in this PR (Kibana)

API reference intro (overlay)

  • Getting started section with chart types table, each linking to documentation and tested API payload examples
  • DSL vs ES|QL data source modes with code snippets
  • ES|QL limitation note, sample dataset note, links to auth and spaces docs
  • "Adapting examples to your own data" guidance
  • Error handling section explaining how to read oneOf validation errors

Endpoint descriptions (route files)

  • Concise, consistent third-person voice across all 5 endpoints
  • Non-obvious behaviors surfaced: ES|QL limitation on create/update, no partial updates, dashboard impact on delete
  • since: '9.4.0' on all availability configs
  • 401/404 response codes documented

Schema property descriptions (~320 fields across config_builder and route schemas)

Replaced tautological descriptions with actionable text across shared and chart-specific schema files. Every description now ends with a period, includes defaults and valid values where available, and provides context beyond restating the field name.

Files improved (config_builder):

  • shared.tslabel, title, description, collapseBy, axis title, legend truncation, panel filters
  • metric_ops.tsreduced_time_range, time_shift, time_scale, formula, field, empty_as_null, static value, column (ES|QL), time_field, percentile, window
  • bucket_ops.ts — date histogram, terms (fields, limit, increase_accuracy, includes/excludes, other_bucket, rank_by with titles), histogram, range
  • format.tsdecimals, suffix, compact, from/to (duration), pattern
  • filter.tsexpression, filter label
  • color.ts — color by value, static color, apply color to
  • charts/xy.ts — ~90 descriptions: layer types, legend, axis config, domain, scale, fitting, curve, overlays, decorations, annotations, reference lines
  • charts/datatable.ts — ~26 descriptions: density, pagination, sorting, alignment, summary rows, one-click filter
  • charts/metric.tssubtitle, compare palette/icon/value, styling (labels, values, icon, secondary)
  • charts/pie.ts — legend, slice labels, donut hole, values display
  • charts/gauge.ts — shapes (bullet/circular), title, subtitle, ticks
  • charts/heatmap.ts — axes, cells, legend, labels
  • charts/tagcloud.ts — orientation, font sizes, caption
  • charts/treemap.ts — legend, labels, metrics, breakdowns
  • charts/waffle.ts — legend, metrics, breakdowns
  • charts/mosaic.ts — legend, breakdowns, group breakdowns
  • charts/legacy_metric.ts — labels, values, font size
  • charts/partition_shared.ts — value display, nested legend
  • charts/region_map.ts — EMS boundaries, join field
  • charts/shared.ts — legend visibility

Files improved (route schemas):

  • common.ts — inline lensItemMetaSchema with 7 described meta fields
  • create.tsid param, overwrite query param
  • search.tsfields, search_fields, query, page, per_page, total

Lens term de-emphasis

  • "Lens documentation" → "visualizations documentation" in overlay
  • Code comment updated in schema
  • Saved object type lens left as-is (it's the actual value)

data_source rename alignment

  • All YAML examples and overlay inline code updated: datasetdata_source, type: indextype: data_view_spec, indexindex_pattern, type: dataViewtype: data_view_reference, idref_id (per [Lens as Code] Use as code dataView schema #260914)

Response and request parameter descriptions (route schema files)

  • Response meta: created_at, updated_at, created_by, updated_by, managed, origin_id, type, id
  • Search request query: fields, search_fields, query, page, per_page
  • Search response meta: page, per_page, total
  • Create: optional id path param, overwrite query param

Examples and code samples (overlay + YAML files)

  • 10 YAML example files for 4 chart types, all validated against a live 9.4 instance
  • cURL and Console code samples on all 5 endpoints

⚠️ Note for reviewers: inlined route schemas

The route schema files (common.ts, create.ts, search.ts) define response meta and request query fields inline rather than referencing shared schemas from kbn-content-management-utils. This is intentional:

Why: ExtendsDeepOptions in kbn-config-schema does not include a meta field — it only supports unknowns. Calling .extendsDeep({ meta: { description: '...' } }) compiles without error (TypeScript doesn't enforce excess property checking at these call sites), but the meta value is silently ignored and never propagated. Descriptions added this way are absent from the generated OpenAPI spec, resulting in undocumented fields in the published API reference. See item 9 in the findings gist for details.

Trade-off: These inline definitions are decoupled from the shared savedObjectSchema and searchOptionsSchemas. If the shared schemas change their types, the Lens route schemas won't automatically follow. The types are identical today and are unlikely to change (stable saved object fields), but this is a conscious trade-off.

Alternatives:

  1. Extend ExtendsDeepOptions to support meta in kbn-config-schema — this would let API teams add descriptions to shared schemas without forking them, and is the cleanest platform-level fix.
  2. Add meta: { description } to the shared schemas in kbn-content-management-utils/src/schema.ts — all content management APIs would inherit descriptions. Lens-specific descriptions (e.g., "Always lens" for type) could then use inline overrides only where needed.

If the team prefers either alternative, these inline definitions can be reverted. Each affected file has a code comment explaining the rationale and pointing to common.ts for the full context.

Changes in companion PR (elastic/docs-content#5645)

50 inline API payload dropdowns across all 13 chart type pages, placed after each individual example and advanced scenario:

  • 27 chart examples (metric, bar, line, area, pie, gauge, table, heatmap, tag cloud, treemap, waffle, mosaic, region map)
  • 13 advanced scenarios (time shifts, reference lines, stacked charts, nested breakdowns, formulas, pivot tables)
  • All 50 payloads pass integration tests against a 9.4 snapshot

Lens overview page: new "Create visualizations with the API" section linking to both stateful and serverless API docs

Integration test findings

All examples validated against a live 9.4 instance. Findings and testing scripts:
https://gist.github.com/florent-leborgne/21996938a5583965e3f0de59da6dedd5

Key items for the team:

  1. metricNoESQL schema missing type: "primary", labels, icon (ES|QL variant is correct)
  2. Null values rejected for optional fields (must omit, not null)
  3. other_bucket runtime expects object, not boolean
  4. Optional id path param missing from POST spec
  5. Filter schema names need human-readable titles
  6. lensPanelFilters description duplicated at array and items level
  7. .extendsDeep() does not support meta — descriptions silently dropped (see item 9 in gist)

Version badges

Added since: '9.4.0' to the availability config on all 5 route definitions so the API docs render "Technical Preview; added in 9.4.0" badges.

Preview

Latest combined preview (Dashboards + Visualizations): https://bump.sh/preview/111e0488-c656-40cb-8379-4d50cf4b1554

@elasticmachine
Copy link
Copy Markdown
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

@florent-leborgne florent-leborgne force-pushed the lens-api-docs branch 2 times, most recently from fe81727 to 7b8c2e5 Compare March 26, 2026 17:45
@florent-leborgne florent-leborgne force-pushed the lens-api-docs branch 2 times, most recently from c000f99 to c93d2bf Compare March 26, 2026 18:34
Comment thread oas_docs/examples/create_pie_visualization_request.yaml Outdated
Comment thread oas_docs/examples/create_pie_visualization_request.yaml
Comment thread oas_docs/examples/create_pie_visualization_request.yaml Outdated
Comment thread oas_docs/makefile
Comment on lines +25 to +28
@node scripts/strip_additional_properties.js oas_docs/output/kibana.yaml
@node scripts/strip_discriminators.js oas_docs/output/kibana.yaml
@node scripts/strip_additional_properties.js oas_docs/output/kibana.serverless.yaml
@node scripts/strip_discriminators.js oas_docs/output/kibana.serverless.yaml
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.

🔴 Critical oas_docs/makefile:25

Running make api-docs fails with ENOENT when the api-docs-postprocess target executes. The Makefile paths oas_docs/output/kibana.yaml resolve to oas_docs/oas_docs/output/kibana.yaml relative to the working directory, but the scripts read files without resolving against REPO_ROOT. This matches the pattern used by api-docs-overlay and api-docs-lint, which expect to run from the oas_docs/ directory. Consider changing paths to output/kibana.yaml to match the convention used in sibling targets, or modify the scripts to resolve paths using REPO_ROOT.

-	@node scripts/strip_additional_properties.js oas_docs/output/kibana.yaml
-	@node scripts/strip_discriminators.js oas_docs/output/kibana.yaml
-	@node scripts/strip_additional_properties.js oas_docs/output/kibana.serverless.yaml
-	@node scripts/strip_discriminators.js oas_docs/output/kibana.serverless.yaml
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file oas_docs/makefile around lines 25-28:

Running `make api-docs` fails with `ENOENT` when the `api-docs-postprocess` target executes. The Makefile paths `oas_docs/output/kibana.yaml` resolve to `oas_docs/oas_docs/output/kibana.yaml` relative to the working directory, but the scripts read files without resolving against `REPO_ROOT`. This matches the pattern used by `api-docs-overlay` and `api-docs-lint`, which expect to run from the `oas_docs/` directory. Consider changing paths to `output/kibana.yaml` to match the convention used in sibling targets, or modify the scripts to resolve paths using `REPO_ROOT`.

florent-leborgne and others added 12 commits April 9, 2026 15:25
Enrich the Visualizations API with overlay content, examples, and
improved descriptions for the upcoming public release in 9.4.

Route and schema improvements:
- Tighter operation descriptions with consistent third-person voice
- Parameter descriptions with valid values, defaults, and field relationships
- Improved error response descriptions
- Fix ignore_global_filters description to explain dashboard filter bar behavior

Overlay (oas_docs/overlays/visualizations.overlays.yaml):
- Tag intro with getting started guide, chart types table with links
  to docs and API payload examples, DSL vs ES|QL mode explanation
- Request/response examples for 4 chart types (metric, XY, pie, data table)
- cURL and Console code samples for all 5 endpoints
- Sample dataset note with link

Example files (oas_docs/examples/):
- 10 new YAML files: 4 request + 4 response examples, plus get and search responses
- All validated against a live 9.4 instance (4/4 DSL examples pass)

Makefile:
- Wired visualizations overlay into the ESS and serverless overlay chains

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add bold anchors to auth blockquote for scannability
- Add common fields sentence after chart types table
- Rename "DSL mode" to "index/data view mode" (overlay + route files)
- Remove stray `time_scale: null` line (invalid JSON) from PUT Console sample

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace ~60 tautological schema descriptions with meaningful, actionable
text across shared and chart-specific schema files. These descriptions
flow into the generated OpenAPI spec, so improving them here permanently
improves the published API reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add descriptions to all response meta fields (created_at, updated_at,
managed, origin_id, etc.), search response pagination fields, and the
create endpoint optional id parameter. Also add "adapting examples" and
error handling guidance to the overlay tag description.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Both schemas spread ...labelSharedProp which already defines `label`,
then immediately override it with an identical local definition. Remove
the dead overrides so the shared definition is the single source of
truth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restore searchOptionsSchemas.page and .perPage references with
.extendsDeep() to add descriptions without changing schema types.
The previous change inadvertently switched these from optional to
required.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace .extendsDeep() calls on shared schema refs with inline schema
definitions that include meta.description directly. This is needed
because .extendsDeep() on maybe()-wrapped schemas does not propagate
descriptions into the generated OpenAPI spec.

Trade-off: these definitions are decoupled from the shared schemas in
kbn-content-management-utils. If the shared schemas add descriptions
in the future, these can be switched back to shared refs. Types must
stay in sync manually until then.

Affected fields:
- common.ts: response meta (type, created_at, updated_at, created_by,
  updated_by, origin_id, managed) and response id
- create.ts: overwrite query param
- search.ts: request query (fields, search_fields) and response meta
  (page, per_page)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract the core description paragraph above the "Get started" heading
so it renders as the tag summary in the API reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ls renames

- terms size → limit in 6 request/response YAML examples
- alignments → labels (with correct alignment: sub-field) in 4 metric examples
- overlay: same fixes in 4 code samples and error guidance text

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update ES|QL warning to mention Dashboards API as a workaround for
  creating ES|QL visualizations (currently blocked on this API)
- Add "Next steps" section pointing to the Dashboards API for embedding
  visualizations as panels (by reference or inline by value)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
florent-leborgne and others added 24 commits April 9, 2026 15:25
…raph

- Add 'When to use Visualizations API vs Dashboards API' section
- Fix auth callout link to include '> Authentication'
- Simplify bridge paragraph: short intro + transition to subsections

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Split into #### Index/data view mode and #### ES|QL mode sub-headings
- Use bullet points for index vs dataView options within Index mode

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add meta.title to schema variants so the generated OpenAPI spec shows
human-readable labels instead of generic 'object' in oneOf/anyOf tabs:

- metric.ts: description on primary/secondary metric oneOf
- bucket_ops.ts: titles on rank_by variants (Alphabetical, Rare terms,
  Significant terms, Column, Custom)
- xy.ts: titles on Y-axis and X-axis extent variants (Full, Focus, Custom)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Label each code sample as 'Action - cURL' and 'Action - Console' so
the dropdown clearly shows which format each sample uses.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Human-readable titles for collapseBy, datatableDensity, lensPanelFilters,
direction/orientation enums, xy annotations, decorations, and fitting schemas.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
These files are regenerated by `make api-docs` and should not be committed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…verlay

Follows the rename in filter.ts from the main merge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ficant option

- create_pie_visualization_request.yaml: donut_hole medium→m, visible→visibility, value_display→values
- bucket_ops.ts: restore missing significant option in rank_by oneOf; remove redundant label definition in bucketHistogramOperationSchema

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ngSchema

Remove alignments, fit, icon (primary) and prefix, label_position
(secondary) from metricStatePrimaryMetricOptionsSchema and
metricStateSecondaryMetricOptionsSchema. These fields don't exist in
main — the equivalent capabilities live in the metricStylingSchema
under the `styling` property. Adding them would change the API surface.

Keep the description improvements on subtitle and compareToSchemaShared.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Align all YAML examples and overlay inline code with the schema rename
from `dataset` to `data_source` (index→data_view_spec, dataView→data_view_reference,
index→index_pattern, id→ref_id) that landed in main via #260914.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Replace "Lens documentation" with "visualizations documentation" in
the overlay narrative text. Update code comment in common.ts.
The saved object type value remains `lens` — only user-facing
prose changes.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add trailing periods to rank_by direction descriptions. Improve
axis title, legend truncation, and panel filters descriptions
with defaults, valid values, and actionable context.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…rity

Add trailing periods and improve terse descriptions across all 15
chart schema files (xy, datatable, metric, pie, gauge, treemap,
tagcloud, heatmap, waffle, mosaic, legacy_metric, region_map,
partition_shared, shared, color). ~228 description edits total.

Only meta.description strings changed — no field names, types,
imports, or code logic altered. Improvements sourced strictly from
visible code context (defaultValue, schema.literal, min/max, JSDoc).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Rewrite opening: direct CRUD + library context, remove marketing
- Move 'Get started' first, comparison section last
- Add required fields note before chart types table
- Rewrite data source modes intro with when-to-use criterion
- Define 'Kibana aggregations' inline
- Fix ES|QL section: remove passive/vague 'best for' phrasing
- Change ES|QL limitation from info to warn callout
- Tighten sample data note
- Expand error handling: add 401/404, fix oneOf jargon
- Replace em dashes with colons throughout

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…schemas

- Add 403 Forbidden to error handling
- Verify chart type docs link is correct
- Strip additionalProperties:false from all schemas in overlay

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Replace vis_api_ meta.id values with readable kebab-case IDs
  (enums: orientation, simple-orientation, direction;
   xy.ts: xy-domain-*, xy-axis-config;
   shared/filter: panel-filters, filter-simple, filter-with-label)
- Add strip_additional_properties.js, strip_discriminators.js
  to oas_docs/scripts/
- Wire api-docs-postprocess target into makefile after api-docs-overlay

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Reapply content improvements (descriptions, punctuation, wording)
without changing meta.id values.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@florent-leborgne
Copy link
Copy Markdown
Member Author

Superseded by a series of smaller PRs

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.

[Docs][Visualizations API] Improve API reference docs

2 participants