Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ spectral lint ~/path-to-spec/schema.yaml --ruleset https://raw.githubusercontent

## Using the Linter

Typically, contributions to the SailPoint OpenAPI specification involve creating a branch of the API specification in Git and making changes within the branch. Rather than having to manually run the linter on each file that was changed in the branch, we have provided [lint.sh](./lint.sh), which will automatically run the linter on only the files that have changed in the branch. To use this script, make sure you are on the correct branch of the API specification repo and run the following command in the root project directory:
Typically, contributions to the SailPoint OpenAPI specification involve creating a branch of the API specification in Git and making changes within the branch. Rather than having to manually run the linter on each file that was changed in the branch, we have provided [lint.sh](./lint.sh), which has two modes.

The first default mode will automatically run the linter on only the files that have changed in the branch. To use this script, make sure you are on the correct branch of the API specification repo and run the following command in the root project directory:

```sh
sh /path/to/lint.sh
```

This script uses the git command `git diff --name-only HEAD master` to print the file paths that have changed, and then it loops through each file and applies the appropriate ruleset based on whether the file is a root spec file, path file, or schema file. This script also has the benefit of referencing the rule files directly from this GitHub repository, so it will always apply the latest rules without the user having to download or synchronize any files.

The second mode is accessed by passing `all` as the first parameter to the script. This will run lint on all yaml files in the path, regardless of if they've changed.

```sh
sh /path/to/lint.sh all
```

## Understanding the Linter Results

The linter will print every problem it finds to stdout. The following is an example of this output:
Expand All @@ -63,3 +71,6 @@ The linter will print the path to the file that it linted, one or more problems,
5. `Operation must have the following ...` is a detailed description of the violation

If the linter reports no problems, then the spec has passed the linter.



19 changes: 14 additions & 5 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
#!/bin/sh

LINTER_URL="https://raw.githubusercontent.com/sailpoint-oss/api-linter/main"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

for file in $(git diff --name-only HEAD master)
args=("$@")

if [ "${args[0]}" = "all" ]
then
files=$(find . -name "*.yaml")
else
files=$(git diff --name-only HEAD main)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you linting agains cloud-api-client-commons? I don't see a main branch on our internal spec repo, just master.

fi

for file in $files
do
if echo $file | grep "sailpoint-api.*" --quiet
then
# Don't ignore unkown format because we want to know if the root API spec is a valid OpenAPI version
spectral lint $file --ruleset "${LINTER_URL}/root-ruleset.yaml"
spectral lint $file --ruleset "${SCRIPT_DIR}/root-ruleset.yaml"
fi

if echo $file | grep paths --quiet
then
spectral lint $file --ruleset "${LINTER_URL}/path-ruleset.yaml" --ignore-unknown-format
spectral lint $file --ruleset "${SCRIPT_DIR}/path-ruleset.yaml" --ignore-unknown-format
fi

if echo $file | grep schemas --quiet
then
spectral lint $file --ruleset "${LINTER_URL}/schema-ruleset.yaml" --ignore-unknown-format
spectral lint $file --ruleset "${SCRIPT_DIR}/schema-ruleset.yaml" --ignore-unknown-format
fi
done
146 changes: 74 additions & 72 deletions path-ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,77 +36,77 @@ rules:
function: parameter-example-check
functionOptions:
rule: 304
path-parameters-must-have-valid-formats-for-numbers-and-integers:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#171"
given: $.[*].parameters[?(@.$ref == null)]
severity: error
then:
function: path-parameter-integer-number-formats
functionOptions:
rule: 171
path-summary-length:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#305"
given: $[*].summary
severity: warn
then:
function: word-count
functionOptions:
maxWordCount: 5
Comment on lines -39 to -54
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all of these path and schema rules commented out?

rule: 305
path-description-html-chars:
message: "{{error}}"
given: $[*].description
severity: error
then:
function: path-descriptions-check
functionOptions:
rule: 405
path-must-have-security-defined:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#104"
given: $[*]
severity: error
then:
function: path-oauth-scope-check
functionOptions:
rule: 104
path-deprecated-apis-should-have-deprecation-and-sunset-dates:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#189"
given: $[*]
severity: warn
then:
function: deprecation
functionOptions:
rule: 189
path-must-have-required-key-on-all-parameters:
description: "Rule 317: Operations must have required key on all parameters: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#317"
given: $.[*].parameters[?(@.$ref == null)]
severity: error
then:
field: required
function: defined
path-must-define-specific-response-codes:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#151"
given: $.[*].responses
severity: error
then:
function: response-validator
functionOptions:
rule: 151
path-boolean-parameters-must-have-default:
message: "Rule 310: Optional boolean values must have a default https://sailpoint-oss.github.io/sailpoint-api-guidelines/#310"
given: $.[*].parameters.[?(@.$ref == null && @.required == false && @.schema.type == 'boolean')].schema
severity: error
then:
field: default
function: defined
path-operation-check:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#400"
given: $
severity: error
then:
function: path-operation-check
functionOptions:
rule: 400
# path-parameters-must-have-valid-formats-for-numbers-and-integers:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#171"
# given: $.[*].parameters[?(@.$ref == null)]
# severity: error
# then:
# function: path-parameter-integer-number-formats
# functionOptions:
# rule: 171
# path-summary-length:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#305"
# given: $[*].summary
# severity: warn
# then:
# function: word-count
# functionOptions:
# maxWordCount: 5
# rule: 305
# path-description-html-chars:
# message: "{{error}}"
# given: $[*].description
# severity: error
# then:
# function: path-descriptions-check
# functionOptions:
# rule: 405
# path-must-have-security-defined:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#104"
# given: $[*]
# severity: error
# then:
# function: path-oauth-scope-check
# functionOptions:
# rule: 104
# path-deprecated-apis-should-have-deprecation-and-sunset-dates:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#189"
# given: $[*]
# severity: warn
# then:
# function: deprecation
# functionOptions:
# rule: 189
# path-must-have-required-key-on-all-parameters:
# description: "Rule 317: Operations must have required key on all parameters: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#317"
# given: $.[*].parameters[?(@.$ref == null)]
# severity: error
# then:
# field: required
# function: defined
# path-must-define-specific-response-codes:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#151"
# given: $.[*].responses
# severity: error
# then:
# function: response-validator
# functionOptions:
# rule: 151
# path-boolean-parameters-must-have-default:
# message: "Rule 310: Optional boolean values must have a default https://sailpoint-oss.github.io/sailpoint-api-guidelines/#310"
# given: $.[*].parameters.[?(@.$ref == null && @.required == false && @.schema.type == 'boolean')].schema
# severity: error
# then:
# field: default
# function: defined
# path-operation-check:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#400"
# given: $
# severity: error
# then:
# function: path-operation-check
# functionOptions:
# rule: 400
# path-parameters-should-have-query-parameter-fields:
# given: $.[get]
# severity: warn
Expand All @@ -122,4 +122,6 @@ rules:
# function: path-query-parameter-check
# functionOptions:
# field: embed
# rule: 158
# rule: 158


34 changes: 17 additions & 17 deletions schema-ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ rules:
functionOptions:
field: description
rule: 303
schema-objects-must-have-required-parameters:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#317"
given: $
severity: error
then:
function: schema-object-field-check
functionOptions:
field: required
rule: 317
# schema-objects-must-have-required-parameters:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#317"
# given: $
# severity: error
# then:
# function: schema-object-field-check
# functionOptions:
# field: required
# rule: 317
schema-properties-must-have-valid-formats-for-numbers-and-integers:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#171"
given: $
Expand All @@ -35,11 +35,11 @@ rules:
function: validate-schema-integer-number-formats
functionOptions:
rule: 171
schema-optional-boolean-properties-must-have-default:
message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#310"
given: $
severity: error
then:
function: schema-boolean-field-check
functionOptions:
rule: 310
# schema-optional-boolean-properties-must-have-default:
# message: "{{error}}: https://sailpoint-oss.github.io/sailpoint-api-guidelines/#310"
# given: $
# severity: error
# then:
# function: schema-boolean-field-check
# functionOptions:
# rule: 310