|
| 1 | +# `map` |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +The `map` command generates a structural map of an API description: |
| 6 | +a hierarchical tree that mirrors the document, like a sitemap for API tooling and agents. |
| 7 | +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. |
| 8 | + |
| 9 | +{% admonition type="warning" name="OpenAPI and AsyncAPI only" %} |
| 10 | +The `map` command is considered an experimental feature. |
| 11 | +This means it's still a work in progress and may go through major changes. |
| 12 | + |
| 13 | +It supports OpenAPI 2.0 through 3.2 and AsyncAPI 2.x and 3.0 descriptions. |
| 14 | +{% /admonition %} |
| 15 | + |
| 16 | +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, |
| 17 | +instead of processing the whole document. |
| 18 | +The tree structure and node summaries are extracted deterministically from the description itself; no external services are involved. |
| 19 | + |
| 20 | +Each node has the following fields: |
| 21 | + |
| 22 | +| Field | Type | Description | |
| 23 | +| ------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 24 | +| title | string | Human-readable name: the API title, path, `operationId`, channel address, component name, tag name, or server URL. | |
| 25 | +| 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`. | |
| 26 | +| pointer | string | Canonical JSON pointer that identifies and addresses the node, for example `#/paths/~1menu/get`. | |
| 27 | +| summary | string | Optional. The node's `summary` field, or its `description` truncated at a word boundary (about 200 characters). | |
| 28 | +| method | string | Optional. HTTP method; present on OpenAPI `Operation` nodes only. | |
| 29 | +| path | string | Optional. URL path; present on OpenAPI `Operation` nodes under `paths` only. | |
| 30 | +| source | object | Optional. Original `{ file, pointer }` location of the node; present when `--source-locations` is used. | |
| 31 | +| nodes | array | Child nodes. | |
| 32 | + |
| 33 | +The tree stops at operations, channels, and named components; |
| 34 | +parameters, responses, messages payloads, and schema internals are the node's content, retrievable through its pointer. |
| 35 | + |
| 36 | +{% admonition type="info" name="Pointers are logical" %} |
| 37 | +Pointers address the logical document structure as authored. |
| 38 | +For multi-file descriptions, note that `redocly bundle` may store referenced components under different keys; |
| 39 | +use `--source-locations` when you need the exact file and location of each node. |
| 40 | +{% /admonition %} |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +```bash |
| 45 | +redocly map <api> |
| 46 | +redocly map <api> [--format=<option>] [--source-locations] [--config=<path>] |
| 47 | +redocly map --version |
| 48 | +``` |
| 49 | + |
| 50 | +## Options |
| 51 | + |
| 52 | +| Option | Type | Description | |
| 53 | +| ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------- | |
| 54 | +| api | string | **REQUIRED.** Path to the API description filename or alias that you want to generate the map for. | |
| 55 | +| --config | string | Specify path to the [configuration file](../configuration/index.md). | |
| 56 | +| --format | string | Format for the output.<br />**Possible values:** `stylish`, `json`. Default value is `stylish`. | |
| 57 | +| --help | boolean | Show help. | |
| 58 | +| --lint-config | string | Specify the severity level for the configuration file. <br/> **Possible values:** `warn`, `error`, `off`. Default value is `warn`. | |
| 59 | +| --source-locations | boolean | Include the original source file and pointer for each node. Useful for multi-file descriptions. | |
| 60 | +| --version | boolean | Show version number. | |
| 61 | + |
| 62 | +## Examples |
| 63 | + |
| 64 | +### Map an OpenAPI description (stylish, default format) |
| 65 | + |
| 66 | +The default output format prints an indented tree, one node per line, with the node title, kind, and pointer: |
| 67 | + |
| 68 | +``` |
| 69 | +Redocly Cafe Root #/ |
| 70 | + Redocly Cafe Info #/info |
| 71 | + paths Paths #/paths |
| 72 | + /menu PathItem #/paths/~1menu |
| 73 | + listMenuItems Operation #/paths/~1menu/get |
| 74 | + createMenuItem Operation #/paths/~1menu/post |
| 75 | + components Components #/components |
| 76 | + schemas NamedSchemas #/components/schemas |
| 77 | + MenuItem Schema #/components/schemas/MenuItem |
| 78 | +``` |
| 79 | + |
| 80 | +### Map an AsyncAPI description |
| 81 | + |
| 82 | +AsyncAPI descriptions map to their own structure: channels, operations (AsyncAPI 3), and message components: |
| 83 | + |
| 84 | +``` |
| 85 | +Account Service Root #/ |
| 86 | + Account Service Info #/info |
| 87 | + channels NamedChannels #/channels |
| 88 | + userSignedup Channel #/channels/userSignedup |
| 89 | + components Components #/components |
| 90 | + messages NamedMessages #/components/messages |
| 91 | + UserSignedUp Message #/components/messages/UserSignedUp |
| 92 | + operations NamedOperations #/operations |
| 93 | + sendUserSignedup Operation #/operations/sendUserSignedup |
| 94 | +``` |
| 95 | + |
| 96 | +### Generate a machine-readable map |
| 97 | + |
| 98 | +Use `--format=json` to get the map as a JSON tree, suitable for further processing: |
| 99 | + |
| 100 | +```bash |
| 101 | +redocly map openapi.yaml --format=json |
| 102 | +``` |
| 103 | + |
| 104 | +```json |
| 105 | +{ |
| 106 | + "title": "Redocly Cafe", |
| 107 | + "kind": "Root", |
| 108 | + "pointer": "#/", |
| 109 | + "nodes": [ |
| 110 | + { |
| 111 | + "title": "listMenuItems", |
| 112 | + "kind": "Operation", |
| 113 | + "pointer": "#/paths/~1menu/get", |
| 114 | + "summary": "List all menu items", |
| 115 | + "method": "get", |
| 116 | + "path": "/menu", |
| 117 | + "nodes": [] |
| 118 | + } |
| 119 | + ] |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +### Include source locations |
| 124 | + |
| 125 | +For descriptions split across multiple files with `$ref`s, |
| 126 | +use `--source-locations` to add the original file and pointer to every node: |
| 127 | + |
| 128 | +```bash |
| 129 | +redocly map openapi.yaml --format=json --source-locations |
| 130 | +``` |
| 131 | + |
| 132 | +```json |
| 133 | +{ |
| 134 | + "title": "/menu", |
| 135 | + "kind": "PathItem", |
| 136 | + "pointer": "#/paths/~1menu", |
| 137 | + "source": { |
| 138 | + "file": "paths/menu.yaml", |
| 139 | + "pointer": "#/" |
| 140 | + }, |
| 141 | + "nodes": [] |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +The `pointer` stays canonical to the logical document, |
| 146 | +while `source` tells you which file the node actually lives in. |
0 commit comments