From 528872cdceab5e2fa63fe484c122df59dbbdb272 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Tue, 7 Jul 2026 11:04:19 +0300 Subject: [PATCH 1/4] feat: add experimental map command --- docs/@v2/commands/map.md | 146 ++ docs/@v2/v2.sidebars.yaml | 2 + .../0001-deterministic-api-map-generation.md | 24 + packages/cli/src/commands/map/index.ts | 51 + .../cli/src/commands/map/print-map/index.ts | 16 + .../cli/src/commands/map/print-map/json.ts | 5 + .../cli/src/commands/map/print-map/stylish.ts | 13 + packages/cli/src/index.ts | 30 + .../api-map/__tests__/build-api-map.test.ts | 571 ++++++++ .../multi-file/components/menu-item.yaml | 2 + .../fixtures/multi-file/openapi.yaml | 13 + .../fixtures/multi-file/paths/menu.yaml | 2 + packages/core/src/api-map/async.ts | 65 + packages/core/src/api-map/build-api-map.ts | 89 ++ packages/core/src/api-map/hooks.ts | 117 ++ packages/core/src/api-map/oas.ts | 78 + packages/core/src/api-map/types.ts | 19 + packages/core/src/index.ts | 2 + packages/core/src/visitors.ts | 32 + tests/e2e/map/map-async2-stylish/async.yaml | 606 ++++++++ tests/e2e/map/map-async2-stylish/snapshot.txt | 55 + .../e2e/map/map-async3-stylish/asyncapi3.yaml | 31 + tests/e2e/map/map-async3-stylish/snapshot.txt | 12 + .../map/map-json/components/menu-item.yaml | 2 + tests/e2e/map/map-json/openapi.yaml | 12 + tests/e2e/map/map-json/paths/menu.yaml | 3 + tests/e2e/map/map-json/snapshot.txt | 90 ++ tests/e2e/map/map-stylish/cafe.yaml | 1261 +++++++++++++++++ tests/e2e/map/map-stylish/snapshot.txt | 73 + tests/e2e/map/map.test.ts | 44 + vitest.config.ts | 2 +- 31 files changed, 3467 insertions(+), 1 deletion(-) create mode 100644 docs/@v2/commands/map.md create mode 100644 docs/adr/0001-deterministic-api-map-generation.md create mode 100644 packages/cli/src/commands/map/index.ts create mode 100644 packages/cli/src/commands/map/print-map/index.ts create mode 100644 packages/cli/src/commands/map/print-map/json.ts create mode 100644 packages/cli/src/commands/map/print-map/stylish.ts create mode 100644 packages/core/src/api-map/__tests__/build-api-map.test.ts create mode 100644 packages/core/src/api-map/__tests__/fixtures/multi-file/components/menu-item.yaml create mode 100644 packages/core/src/api-map/__tests__/fixtures/multi-file/openapi.yaml create mode 100644 packages/core/src/api-map/__tests__/fixtures/multi-file/paths/menu.yaml create mode 100644 packages/core/src/api-map/async.ts create mode 100644 packages/core/src/api-map/build-api-map.ts create mode 100644 packages/core/src/api-map/hooks.ts create mode 100644 packages/core/src/api-map/oas.ts create mode 100644 packages/core/src/api-map/types.ts create mode 100644 tests/e2e/map/map-async2-stylish/async.yaml create mode 100644 tests/e2e/map/map-async2-stylish/snapshot.txt create mode 100644 tests/e2e/map/map-async3-stylish/asyncapi3.yaml create mode 100644 tests/e2e/map/map-async3-stylish/snapshot.txt create mode 100644 tests/e2e/map/map-json/components/menu-item.yaml create mode 100644 tests/e2e/map/map-json/openapi.yaml create mode 100644 tests/e2e/map/map-json/paths/menu.yaml create mode 100644 tests/e2e/map/map-json/snapshot.txt create mode 100644 tests/e2e/map/map-stylish/cafe.yaml create mode 100644 tests/e2e/map/map-stylish/snapshot.txt create mode 100644 tests/e2e/map/map.test.ts diff --git a/docs/@v2/commands/map.md b/docs/@v2/commands/map.md new file mode 100644 index 0000000000..90c9781935 --- /dev/null +++ b/docs/@v2/commands/map.md @@ -0,0 +1,146 @@ +# `map` + +## Introduction + +The `map` command generates a structural map of an API description: +a hierarchical tree that mirrors the document, like a sitemap for API tooling and agents. +Every node in the tree represents a retrievable section of the description — an operation, a channel, a named component, a webhook, a server, or a tag — and is addressed by a canonical JSON pointer. + +{% admonition type="warning" name="OpenAPI and AsyncAPI only" %} +The `map` command is considered an experimental feature. +This means it's still a work in progress and may go through major changes. + +It supports OpenAPI 2.0 through 3.2 and AsyncAPI 2.x and 3.0 descriptions. +{% /admonition %} + +The API map is designed as a compact index that tools — including LLM-based agents — can navigate to decide which parts of an API description to retrieve, +instead of processing the whole document. +The tree structure and node summaries are extracted deterministically from the description itself; no external services are involved. + +Each node has the following fields: + +| Field | Type | Description | +| ------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| title | string | Human-readable name: the API title, path, `operationId`, channel address, component name, tag name, or server URL. | +| kind | string | Node type name from Redocly's internal type system, for example `Root`, `Info`, `Server`, `Tag`, `Paths`, `PathItem`, `Operation`, `Channel`, `Components`, `NamedSchemas`, or `Schema`. | +| pointer | string | Canonical JSON pointer that identifies and addresses the node, for example `#/paths/~1menu/get`. | +| summary | string | Optional. The node's `summary` field, or its `description` truncated at a word boundary (about 200 characters). | +| method | string | Optional. HTTP method; present on OpenAPI `Operation` nodes only. | +| path | string | Optional. URL path; present on OpenAPI `Operation` nodes under `paths` only. | +| source | object | Optional. Original `{ file, pointer }` location of the node; present when `--source-locations` is used. | +| nodes | array | Child nodes. | + +The tree stops at operations, channels, and named components; +parameters, responses, messages payloads, and schema internals are the node's content, retrievable through its pointer. + +{% admonition type="info" name="Pointers are logical" %} +Pointers address the logical document structure as authored. +For multi-file descriptions, note that `redocly bundle` may store referenced components under different keys; +use `--source-locations` when you need the exact file and location of each node. +{% /admonition %} + +## Usage + +```bash +redocly map +redocly map [--format=