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.

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
  
  # 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   Only output results with severity equal to or greater than --fail-severity
  -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                    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            Disable telemetry for this command invocation. Overrides config and env.
                                - Config path: [ telemetry.enabled ]
                                - Env var    : [ KONGCTL_NO_TELEMETRY ]
                                - Default    : [ false ]
      --no-trunc                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               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; 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!