A Neovim plugin for managing Kubernetes YAML schema modelines. Automatically detect or search for the correct schema based on your resource's apiVersion and kind, and insert the appropriate YAML language server modeline.
- Auto-detection: Automatically detect the schema based on
apiVersionandkindin your YAML file - Multi-document support: Works with files containing multiple YAML documents separated by
--- - Manual search: Browse and search through available Kubernetes schemas
- Filter support: Pre-filter schemas by name or description
- Precise matching: Deterministic schema matching based on exact API group, version, and kind
- Integration: Works with your existing
vim.ui.selectbackend (Telescope, fzf-lua, Snacks, etc.) - Async fetching: Uses plenary.curl for non-blocking HTTP requests
- Neovim >= 0.9.0
- plenary.nvim
{
"r35krag0th/kube-schemas.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
ft = "yaml",
opts = {
-- Optional: customize the catalog URL
-- catalog_url = "https://schemas.r35.io/api/json/catalog.json",
},
keys = {
{ "<localleader>yks", "<cmd>KubeSchemas search<cr>", desc = "Search Kubernetes schemas" },
{ "<localleader>yka", "<cmd>KubeSchemas auto<cr>", desc = "Auto-detect Kubernetes schema" },
},
}Automatically detect the schema based on apiVersion and kind in the current YAML document. Place your cursor in the document you want to add a schema to and run:
:KubeSchemas autoExample:
Given a file with:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-appRunning :KubeSchemas auto will insert:
# yaml-language-server: $schema=https://schemas.r35.io/kubernetes/1.31/deployment-apps-v1.json
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-appMulti-document support:
For files with multiple YAML documents, the plugin will detect the document containing your cursor and insert the schema modeline at the beginning of that specific document:
---
# yaml-language-server: $schema=https://schemas.r35.io/kubernetes/1.31/service-v1.json
apiVersion: v1
kind: Service
metadata:
name: my-service
---
# yaml-language-server: $schema=https://schemas.r35.io/kubernetes/1.31/deployment-apps-v1.json
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-appOpen a picker to browse and search available schemas:
:KubeSchemas searchOptionally, provide a search query to pre-filter results:
:KubeSchemas search deployment
:KubeSchemas search helm release
:KubeSchemas search istioThe plugin can be configured via the setup() function:
require("kube-schemas").setup({
catalog_url = "https://schemas.r35.io/api/json/catalog.json",
})| Option | Type | Default | Description |
|---|---|---|---|
catalog_url |
string | https://schemas.r35.io/api/json/catalog.json |
URL to fetch the schema catalog from |
The plugin supports any JSON catalog that follows the schema store format. Here are some options:
Default (recommended for Kubernetes):
catalog_url = "https://schemas.r35.io/api/json/catalog.json"This catalog includes comprehensive Kubernetes core resources and CRDs (Custom Resource Definitions) for popular tools like Flux, Istio, cert-manager, and more.
SchemaStore.org:
catalog_url = "https://www.schemastore.org/api/json/catalog.json"This is a general-purpose schema catalog. Note that SchemaStore.org is unlikely to have many Kubernetes CRDs or version-specific core resources. It's better suited for general YAML files (GitHub Actions, Docker Compose, etc.) rather than Kubernetes-specific resources.
- The plugin fetches a catalog of Kubernetes schemas from a configurable URL
- For auto-detection, it parses the current buffer to find
apiVersionandkind - It matches these against the schema catalog using the resource kind, API group, and version
- The appropriate YAML language server modeline is inserted at the top of the file
- Your YAML language server (yaml-language-server) will use this schema for validation and completion
The default catalog URL (https://schemas.r35.io/api/json/catalog.json) aggregates schemas from multiple sources:
- Kubernetes Core Resources: Generated from official Kubernetes OpenAPI specifications
- CRD Catalog: datreeio/CRDs-catalog - Community-maintained JSON schemas for popular Kubernetes Custom Resource Definitions
- SchemaStore.org: SchemaStore/schemastore - General-purpose JSON schema catalog
The plugin includes comprehensive unit tests that verify schema matching against the live catalog.
# Run tests once
mise run test
# Run tests in watch mode (requires entr)
mise run test-watchTests cover:
- Core Kubernetes resources (v1)
- Grouped Kubernetes resources (apps/v1, batch/v1, networking.k8s.io/v1)
- Custom Resource Definitions (CRDs) from popular tools (Flux, Istio, cert-manager)
- Edge cases and error handling
This plugin was inspired by:
- yaml-companion.nvim - Dynamic YAML schema selection for Neovim
- schema-companion.nvim - Schema companion for various file types
MIT