kongctl lint

Uses: kongctl

kongctl lint validates one or more configuration files against a ruleset. Linting is powered by vacuum, so rulesets use the same Spectral-compatible format as deck file lint.

There are a few key concepts to understand for linting with kongctl:

  • Rules define selectors, functions and the failure severity to apply to the provided file.
  • Selectors define a filter to apply to the input file which selects the objects to validate. Selectors are specified in the given keyword on a rule. Selectors are expressed using JSONPath syntax.
  • Functions accept the filtered values and perform a validation returning information when there are violations.
  • Rulesets are collections of rules.

For a complete list of available rules, see the vacuum documentation.

kongctl lint example

APIs in a kongctl declarative configuration file are defined in the apis block. To make sure every API is documented, you may want to validate that each one has a description.

Here is a sample ruleset file containing a single rule that accomplishes this:

rules:
  api-description-defined:
    description: "APIs must have a description"
    given: $.apis[*]
    severity: error
    then:
      field: description
      function: truthy

The JSONPath selector specified in given selects every API under the apis key from the incoming file. For each of those objects, the truthy function checks that the description field is set.

Assume you have the following declarative configuration file (kong.yaml):

apis:
  - ref: tasks-api
    name: Task API

Validating this configuration against the example ruleset, stored in ruleset.yaml, results in the following violation:

kongctl lint -f kong.yaml -r ruleset.yaml

Result:

Linting Violations: 1
Failures: 1

kong.yaml:1:1: [error] APIs must have a description: `description` must be set

Adding a description to the API resolves this violation:

apis:
  - ref: tasks-api
    name: Task API
    description: Create and track tasks

Run kongctl with the new ruleset:

kongctl lint -f kong.yaml -r ruleset.yaml; echo $?

Result:

0

When kongctl lint finds violations at or above the --fail-severity level, the command returns a non-zero exit code. You can use this to stop a CI/CD pipeline before a problematic configuration is applied. To lint multiple files, pass a directory to -f and use -R to process it recursively.

Lint expanded declarative configuration v1.28+

By default, kongctl lint checks each input as written, including template definitions. Use --expand to lint values from local !file includes, principal !csv inputs, and _templates and _extends inheritance. Rules can then check included and inherited values after resource overrides apply.

For example, save a shared API template in templates.yaml:

_templates:
  documented-api:
    description: Create and track tasks

Use the template in kong.yaml:

apis:
  - _extends: documented-api
    ref: tasks-api
    name: Task API

Lint both files with the ruleset.yaml file from the kongctl lint example:

kongctl lint -f templates.yaml -f kong.yaml -r ruleset.yaml --expand

The API passes the rule because its expanded configuration contains the inherited description. Without --expand, the rule reports a missing description on the API.

All selected inputs share template definitions, so include both the template files and the files that use them. Each input is linted separately after expansion; rules can’t detect duplicates across files. Empty inputs, including files that only define templates, are skipped. Templates are checked where they’re used. The command fails if nothing remains to lint.

For more information, see reusable configuration templates.

Input files and includes

With --expand, you can pass YAML files (.yaml or .yml), directories, or standard input (-f -). Use -R to search subdirectories. URL inputs aren’t supported. Each selected input must contain one YAML document; split documents separated by --- into separate files.

!file paths resolve relative to the file containing the tag, including tags inherited through templates. Includes must stay within the source root:

  • For a file input, the root is its parent directory.
  • For a directory input, the root is that directory.
  • For standard input, the root is the working directory, which also resolves relative include paths.

Included fragments are checked as part of the file that includes them. A fragment also selected as an input is checked independently, including lists and scalars. Keep fragments outside selected inputs to avoid independent checks. The vacuum linter may report index-failure for standalone scalars.

Expansion limits and findings

!env (including store: true), !ref, !secret, and lookup tags remain unresolved placeholders. Expansion doesn’t read environment values, fetch secrets, or contact Konnect. Rules that expect concrete values must account for these placeholders. Existing OpenAPI $ref resolution and ruleset inheritance can still access the network.

Expansion checks YAML, tag, and template syntax. It doesn’t apply defaults, validate resource schemas, or check the types of fields containing !env. Passing lint doesn’t establish that configuration is ready to apply. Use kongctl plan for that validation.

Findings identify the input filename, but line and column numbers refer to the expanded content held in memory. They may differ from the original source locations. Text findings append (expanded) to the message; JSON and YAML findings include expanded: true. Expanded content isn’t saved to disk. Expansion errors fail the command and identify the source; template errors also report a position.

Command usage

Usage:
  kongctl lint [flags]

Aliases:
  lint, li

Examples:
  # Lint a single file
  kongctl lint -f config.yaml -r ruleset.yaml
  
  # Lint all YAML files in a directory
  kongctl lint -f ./configs/ -r ruleset.yaml
  
  # Lint recursively with JSON output
  kongctl lint -f ./configs/ -R -r ruleset.yaml --output json
  
  # Only show errors (not warnings/info/hints)
  kongctl lint -f config.yaml -r ruleset.yaml --fail-severity error -D
  
  # Fail on warnings and above
  kongctl lint -f config.yaml -r ruleset.yaml --fail-severity warn
  
  # Lint declarative configuration after expanding templates and !file
  kongctl lint -f ./templates/ -f ./team/ -r ruleset.yaml --expand
  
  # Read from stdin
  cat config.yaml | kongctl lint -f - -r ruleset.yaml


Flags:
      --color-theme string                   Configures the CLI UI/theme (prompt, tables, TUI elements).
                                             - Config path: [ color-theme ]
                                             - Examples   : [ auto, 0_x_96_f, 12_bit_rainbow, 13_th_floor, 3024_day ]
                                             - List       : [ kongctl list themes ] (default "auto")
      --config-file string                   Path to the configuration file to load.
                                             - Environment variable: KONGCTL_CONFIG_FILE (overridden by this flag)
                                             - Default: [ $XDG_CONFIG_HOME/kongctl/config.yaml ]
  -D, --display-only-failures[=true|false]   Only output results with severity equal to or greater than --fail-severity
      --expand[=true|false]                  Lint declarative configuration after including !file content and expanding _templates/_extends across all inputs (!env, !ref and !secret stay unresolved)
  -F, --fail-severity string                 Results of this severity or above will trigger a failure exit code. Allowed: [ error | warn | info | hint ] (default "error")
  -f, --filename strings                     Input file(s) or directory to lint. Use '-' to read from stdin.
  -h, --help[=true|false]                    help for lint
      --log-file string                      Write execution logs to the specified file instead of STDERR.
                                             - Config path: [ log-file ]
      --log-level string                     Configures the logging level. Execution logs are written to STDERR.
                                             - Config path: [ log-level ]
                                             - Allowed    : [ trace|debug|info|warn|error ] (default "error")
      --no-telemetry[=true|false]            Disable telemetry for this command invocation. Overrides config and env.
                                             - Config path: [ telemetry.enabled ]
                                             - Env var    : [ KONGCTL_NO_TELEMETRY ]
                                             - Default    : [ false ]
      --no-trunc[=true|false]                Preserve full cell widths in static text tables beyond terminal width.
                                             Does not change column selection, UUID formatting, or explicit string slices.
                                             - Config path: [ text.no-trunc ]
                                             - Default    : [ false ]
  -o, --output string                        Configures the format of data written to STDOUT.
                                             - Config path: [ output ]
                                             - Allowed    : [ json|yaml|text ] (default "text")
  -p, --profile string                       Specify the profile to use for this command. (default "default")
  -R, --recursive[=true|false]               Process the directory used in -f, --filename recursively
  -r, --ruleset string                       Local YAML or JSON ruleset for vacuum (partial Spectral compatibility; no custom functions). Input tags/templates are not expanded unless --expand is set; extends paths use the working directory (URLs allowed in extends).
      --text-id-format string                Configure UUID rendering in static text-table ID columns.
                                             - Config path: [ text.id-format ]
                                             - Allowed    : [ compact|full ]
                                             - Default    : [ compact ]
      --text-layout string                   Configure static text-table column selection.
                                             - Config path: [ text.layout ]
                                             - Allowed    : [ compact|auto|wide ]
                                             - Default    : [ compact ]

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!