OpenAPI grammar for tree-sitter. Parses OpenAPI (Swagger) 2.0, OpenAPI 3.0.x, 3.1.x, and 3.2.x documents in YAML and JSON, with Markdown injection into description fields.
- Swagger 2.0 (OpenAPI 2.0) –
swagger: "2.0",host,basePath,definitions,securityDefinitions, etc. - OpenAPI 3.0.x –
openapi: "3.0.x",servers,components,paths, etc. - OpenAPI 3.1.x – same as 3.0 with
jsonSchemaDialectand other 3.1 features - OpenAPI 3.2.x – same as 3.1 with 3.2 dialect and extensions
Highlighting and structure are version-agnostic; all of the above use the same YAML/JSON grammar and OpenAPI-aware queries.
- YAML – Full YAML OpenAPI specs (block/flow, scalars, anchors, etc.)
- JSON – JSON OpenAPI specs
- Root and fragment files – Supports both full root documents and standalone fragment files referenced via
$ref(e.g. a single schema, path item, parameter, or response in its own file). All common OpenAPI and JSON Schema keys are highlighted in fragments. - Markdown in descriptions –
descriptionvalues are injected with tree-sitter-markdown for highlighting in editors that support language injection (Neovim, Helix, Zed)
This package ships two grammars:
| Grammar | Scope | File types | Use case |
|---|---|---|---|
openapi |
source.openapi |
yaml, yml | YAML OpenAPI docs |
openapi_json |
source.openapi.json |
json | JSON OpenAPI docs |
npm install tree-sitter-openapiAdd to your parser config:
openapi = { install_info = { url = "https://github.com/.../tree-sitter-openapi", files = { "src/parser.c", "src/scanner.c" } } }(Adjust url and grammar paths for the openapi and openapi_json grammars as required by nvim-treesitter’s multi-grammar support.)
- Build both grammars:
npm run build(runstree-sitter generatein each grammar directory) - Install native addon:
npm install - Run tests:
npm test - Playground:
npm start
MIT. The YAML grammar is adapted from tree-sitter-yaml (MIT). The JSON grammar is adapted from tree-sitter-json (MIT).
100% Written by AI