Setup linting for your OpenAPI Spec
To ensure that your SDKs are free of bugs & ergonomic (i.e. meaningful namespaces, succinct method name, and legible class names), Konfig has created a comprehensive set of rules that your OAS must pass. All lint rules and their explanations are documented here.
Methods
There are four ways to lint your spec:
Required Setup
Ensure you have the konfig-cli
installed by running
_10npm install -g konfig-cli
GitHub Action Setup
To setup GitHub Action copy the following template to .github/workflows/konfig-lint.yaml
and configure the following values:
- Target branch
- Path to OAS
Commit and push the generated file:
_19~/Git/my-repo_19❯ git status_19On branch master_19Your branch is up to date with 'origin/master'._19_19Untracked files:_19 (use "git add <file>..." to include in what will be committed)_19 .github/_19_19nothing added to commit but untracked files present (use "git add" to track)_19_19~/Git/my-repo_19❯ git add -A_19_19~/Git/my-repo_19❯ git commit -m "Commit Konfig lint GitHub action"_19[master 83d1f7e] Commit Konfig lint GitHub action_19 1 file changed, 26 insertions(+)_19 create mode 100644 .github/workflows/konfig-lint.yaml
On every PR or commit to your target branch the lint workflow will fail if any warnings or errors occur when linting your OAS.
VSCode Extension or CLI Setup
Initialize your target repository (the one that has your OpenAPI spec) with:
_10❯ konfig init -s_10Downloading Konfig's lint rules... done_10Setting up Spectral... done
Commit the generated files
_25~/Git/my-repo_25❯ git status_25On branch master_25Your branch is ahead of 'origin/master' by 1 commit._25 (use "git push" to publish your local commits)_25_25Untracked files:_25 (use "git add <file>..." to include in what will be committed)_25 .konfig/_25 .spectral.yaml_25 .vscode/_25_25nothing added to commit but untracked files present (use "git add" to track)_25_25~/Git/my-repo_25❯ git add -A_25_25~/Git/my-repo_25❯ git commit -m "Commit Konfig linting ruleset and VSCode settings"_25[master 06c577e] Commit Konfig linting ruleset and VSCode settings_25 4 files changed, 28 insertions(+)_25 create mode 100644 .konfig/ruleset.js_25 create mode 100644 .spectral.yaml_25 create mode 100644 .vscode/extensions.json_25 create mode 100644 .vscode/settings.json
To update your ruleset to the latest verson simply run
_10konfig init -s
And commit the updated ruleset.
Linting with VSCode Extension
When opening VSCode to your repo, you will be prompted to install the Spectral extension.
Click Install
to install the Spectral extension. When viewing any OAS, you will see inline errors.
To see all the errors, open the "PROBLEMS" tab at the bottom of VSCode.
Make sure that showing all problems is enabled
Linting with CLI
To lint with CLI run konfig lint
inside the directory that contains your konfig.yaml
file.
_10❯ konfig lint_10_10/api.yaml_10 22:10 warning operation-operationId Operation must have "operationId" for generated SDK method names. paths./pet.post_10_10✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints)
REST API
For access to the REST API please setup a time to talk and we will get you setup.