From eac560b35b45c3850f4aa1b6d9ed0e52a37ee9d4 Mon Sep 17 00:00:00 2001 From: Justin Kalland Date: Thu, 25 Jun 2020 08:13:19 +0200 Subject: [PATCH 1/6] Add support for OpenAPI --- .automation/test/openapi/README.md | 13 +++ .automation/test/openapi/openapi_bad_1.yml | 1 + .automation/test/openapi/openapi_bad_2.json | 3 + .automation/test/openapi/openapi_good_1.yml | 13 +++ .automation/test/openapi/openapi_good_2.json | 23 ++++++ Dockerfile | 4 +- README.md | 2 + TEMPLATES/.openapirc.yml | 9 +++ lib/linter.sh | 83 +++++++++++++++++++- 9 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 .automation/test/openapi/README.md create mode 100644 .automation/test/openapi/openapi_bad_1.yml create mode 100644 .automation/test/openapi/openapi_bad_2.json create mode 100644 .automation/test/openapi/openapi_good_1.yml create mode 100644 .automation/test/openapi/openapi_good_2.json create mode 100644 TEMPLATES/.openapirc.yml diff --git a/.automation/test/openapi/README.md b/.automation/test/openapi/README.md new file mode 100644 index 00000000..8e77fdbf --- /dev/null +++ b/.automation/test/openapi/README.md @@ -0,0 +1,13 @@ +# OpenAPI Test Cases +This folder holds the test cases for **OpenAPI**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/openapi/openapi_bad_1.yml b/.automation/test/openapi/openapi_bad_1.yml new file mode 100644 index 00000000..6c86b1b4 --- /dev/null +++ b/.automation/test/openapi/openapi_bad_1.yml @@ -0,0 +1 @@ +openapi: '3.0.0' diff --git a/.automation/test/openapi/openapi_bad_2.json b/.automation/test/openapi/openapi_bad_2.json new file mode 100644 index 00000000..b0b97ddb --- /dev/null +++ b/.automation/test/openapi/openapi_bad_2.json @@ -0,0 +1,3 @@ +{ + "openapi": "3.0.0" +} diff --git a/.automation/test/openapi/openapi_good_1.yml b/.automation/test/openapi/openapi_good_1.yml new file mode 100644 index 00000000..eb4924a1 --- /dev/null +++ b/.automation/test/openapi/openapi_good_1.yml @@ -0,0 +1,13 @@ +openapi: 3.0.0 +info: + title: Example + version: '1.0' + contact: + name: Justin Kalland + email: justin@kalland.com + description: Test for super-linter +servers: + - url: 'http://localhost:3000' +paths: {} +tags: + - name: example diff --git a/.automation/test/openapi/openapi_good_2.json b/.automation/test/openapi/openapi_good_2.json new file mode 100644 index 00000000..93f59635 --- /dev/null +++ b/.automation/test/openapi/openapi_good_2.json @@ -0,0 +1,23 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Example", + "version": "1.0", + "contact": { + "name": "Justin Kalland", + "email": "justin@kalland.com" + }, + "description": "Test for super-linter" + }, + "servers": [ + { + "url": "http://localhost:3000" + } + ], + "paths": {}, + "tags": [ + { + "name": "example" + } + ] +} diff --git a/Dockerfile b/Dockerfile index 49a5dbb1..b25a7b1f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ RUN apk add --no-cache \ libxml2-utils perl \ ruby ruby-dev ruby-bundler ruby-rdoc make \ py3-setuptools ansible-lint \ - go \ + go \ openjdk8-jre \ php7 \ ca-certificates less ncurses-terminfo-base \ @@ -72,6 +72,7 @@ RUN npm config set package-lock false \ eslint-plugin-jest \ stylelint \ stylelint-config-standard \ + @stoplight/spectral \ && npm --no-cache install \ markdownlint-cli \ jsonlint prettyjson \ @@ -168,6 +169,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ VALIDATE_ENV=${VALIDATE_ENV} \ VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \ + VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ RUN_LOCAL=${RUN_LOCAL} \ TEST_CASE_RUN=${TEST_CASE_RUN} \ diff --git a/README.md b/README.md index 218a30d5..638ed28b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | | **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | +| **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | ## How to use To use this **GitHub** Action you will need to complete the following: @@ -144,6 +145,7 @@ and won't run anything unexpected. | **VALIDATE_CSS** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the language. | | **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). | | **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | diff --git a/TEMPLATES/.openapirc.yml b/TEMPLATES/.openapirc.yml new file mode 100644 index 00000000..fdf641e1 --- /dev/null +++ b/TEMPLATES/.openapirc.yml @@ -0,0 +1,9 @@ +--- + +########################## +########################## +## OpenAPI Linter rules ## +########################## +########################## + +extends: spectral:oas diff --git a/lib/linter.sh b/lib/linter.sh index 9bad8c8b..7b90ae32 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -54,6 +54,9 @@ POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Pat # CSS Vars CSS_FILE_NAME='.stylelintrc.json' # Name of the file CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to the CSS lint rules +# OpenAPI Vars +OPENAPI_FILE_NAME='.openapirc.yml' # Name of the file +OPENAPI_LINTER_RULES="$DEFAULT_RULES_LOCATION/$OPENAPI_FILE_NAME" # Path to the OpenAPI lint rules ####################################### # Linter array for information prints # @@ -61,7 +64,7 @@ CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to th LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" - "stylelint" "dotenv-linter" "powershell" "ktlint") + "stylelint" "dotenv-linter" "powershell" "ktlint" "spectral") ############################# # Language array for prints # @@ -69,7 +72,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' - 'ENV' 'POWERSHELL' 'KOTLIN') + 'ENV' 'POWERSHELL' 'KOTLIN' 'OPENAPI') ################### # GitHub ENV Vars # @@ -102,6 +105,7 @@ VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate lang VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors @@ -149,6 +153,7 @@ FILE_ARRAY_POWERSHELL=() # Array of files to check FILE_ARRAY_CSS=() # Array of files to check FILE_ARRAY_ENV=() # Array of files to check FILE_ARRAY_KOTLIN=() # Array of files to check +FILE_ARRAY_OPENAPI=() # Array of files to check ############ # Counters # @@ -175,6 +180,7 @@ ERRORS_FOUND_POWERSHELL=0 # Count of errors found ERRORS_FOUND_CSS=0 # Count of errors found ERRORS_FOUND_ENV=0 # Count of errors found ERRORS_FOUND_KOTLIN=0 # Count of errors found +ERRORS_FOUND_OPENAPI=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -556,6 +562,19 @@ LintAnsibleFiles() fi fi } + +################################################################################ +#### Function DetectOpenAPIFile ################################################ +DetectOpenAPIFile() +{ + egrep '"openapi":|"swagger":|^openapi:|^swagger:' $GITHUB_WORKSPACE/$1 > /dev/null + if [ $? -eq 0 ]; then + return 0 + else + return 1 + fi +} + ################################################################################ #### Function GetGitHubVars #################################################### GetGitHubVars() @@ -756,6 +775,7 @@ GetValidationInfo() VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}') VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)}') VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}') + VALIDATE_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -782,7 +802,8 @@ GetValidationInfo() -n "$VALIDATE_POWERSHELL" || \ -n "$VALIDATE_CSS" || \ -n "$VALIDATE_ENV" || \ - -n "$VALIDATE_KOTLIN" ]]; then + -n "$VALIDATE_KOTLIN" || \ + -n "$VALIDATE_OPENAPI" ]]; then ANY_SET="true" fi @@ -1094,6 +1115,19 @@ GetValidationInfo() VALIDATE_KOTLIN="true" fi + ####################################### + # Validate if we should check OPENAPI # + ####################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_OPENAPI" ]]; then + # OPENAPI flag was not set - default to false + VALIDATE_OPENAPI="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_OPENAPI="true" + fi ####################################### # Print which linters we are enabling # @@ -1208,6 +1242,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [KOTLIN] files in code base...") fi + if [[ "$VALIDATE_OPENAPI" == "true" ]]; then + PRINT_ARRAY+=("- Validating [OPENAPI] files in code base...") + else + PRINT_ARRAY+=("- Excluding [OPENAPI] files in code base...") + fi ############################## # Validate Ansible Directory # @@ -1391,6 +1430,12 @@ BuildFileList() # Append the file to the array # ################################ FILE_ARRAY_YML+=("$FILE") + ############################ + # Check if file is OpenAPI # + ############################ + if DetectOpenAPIFile $FILE; then + FILE_ARRAY_OPENAPI+=("$FILE") + fi ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -1403,6 +1448,12 @@ BuildFileList() # Append the file to the array # ################################ FILE_ARRAY_JSON+=("$FILE") + ############################ + # Check if file is OpenAPI # + ############################ + if DetectOpenAPIFile $FILE; then + FILE_ARRAY_OPENAPI+=("$FILE") + fi ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -2122,7 +2173,8 @@ Footer() [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \ [ "$ERRORS_FOUND_CSS" -ne 0 ] || \ [ "$ERRORS_FOUND_ENV" -ne 0 ] || \ - [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then + [ "$ERRORS_FOUND_KOTLIN" -ne 0 ] || \ + [ "$ERRORS_FOUND_OPENAPI" -ne 0 ]; then # Failed exit echo "Exiting with errors found!" exit 1 @@ -2184,6 +2236,7 @@ RunTestCases() TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" + TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(yml\|yaml\|json\)\$" ################# # Footer prints # @@ -2526,6 +2579,28 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then LintCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi +################### +# OPENAPI LINTING # +################### +if [ "$VALIDATE_OPENAPI" == "true" ]; then + # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file + if [ "$VALIDATE_ALL_CODEBASE" == "true" ]; then + LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1)) + for FILE in "${LIST_FILES[@]}" + do + if DetectOpenAPIFile $FILE; then + FILE_ARRAY_OPENAPI+=("$FILE") + fi + done + fi + + ########################## + # Lint the OpenAPI files # + ########################## + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" +fi + ########## # Footer # ########## From 37f6828d1ecbb30ef3090caf46cfeb4f1fd3ab61 Mon Sep 17 00:00:00 2001 From: Justin Kalland Date: Thu, 25 Jun 2020 11:49:09 +0200 Subject: [PATCH 2/6] Fix OpenAPI tests being run by JSON & YAML Tests are run by file extension. The [JSON] and [YAML] tests were running the _bad_ [OPENAPI] tests and expecting them to fail. For [OPENAPI] the _bad_ tests are syntactically good JSON/YAML but bad OAS. --- .automation/test/openapi/README.md | 3 ++- .../openapi/{openapi_bad_1.yml => openapi_bad_1.ymlopenapi} | 0 .../openapi/{openapi_bad_2.json => openapi_bad_2.jsonopenapi} | 0 .../openapi/{openapi_good_1.yml => openapi_good_1.ymlopenapi} | 0 .../{openapi_good_2.json => openapi_good_2.jsonopenapi} | 0 lib/linter.sh | 2 +- 6 files changed, 3 insertions(+), 2 deletions(-) rename .automation/test/openapi/{openapi_bad_1.yml => openapi_bad_1.ymlopenapi} (100%) rename .automation/test/openapi/{openapi_bad_2.json => openapi_bad_2.jsonopenapi} (100%) rename .automation/test/openapi/{openapi_good_1.yml => openapi_good_1.ymlopenapi} (100%) rename .automation/test/openapi/{openapi_good_2.json => openapi_good_2.jsonopenapi} (100%) diff --git a/.automation/test/openapi/README.md b/.automation/test/openapi/README.md index 8e77fdbf..6f5d2c24 100644 --- a/.automation/test/openapi/README.md +++ b/.automation/test/openapi/README.md @@ -2,7 +2,8 @@ This folder holds the test cases for **OpenAPI**. ## Additional Docs -No Additional information is needed for this test case. +The `_bad_` tests are valid `.yml`/`.json` but invalid OpenAPI specs. +The test extensions used are `.ymlopenapi`/`.jsonopenapi` instead of `.yml`/`.json`. This is to prevent the [YAML] and [JSON] tests from picking them up. ## Good Test Cases The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. diff --git a/.automation/test/openapi/openapi_bad_1.yml b/.automation/test/openapi/openapi_bad_1.ymlopenapi similarity index 100% rename from .automation/test/openapi/openapi_bad_1.yml rename to .automation/test/openapi/openapi_bad_1.ymlopenapi diff --git a/.automation/test/openapi/openapi_bad_2.json b/.automation/test/openapi/openapi_bad_2.jsonopenapi similarity index 100% rename from .automation/test/openapi/openapi_bad_2.json rename to .automation/test/openapi/openapi_bad_2.jsonopenapi diff --git a/.automation/test/openapi/openapi_good_1.yml b/.automation/test/openapi/openapi_good_1.ymlopenapi similarity index 100% rename from .automation/test/openapi/openapi_good_1.yml rename to .automation/test/openapi/openapi_good_1.ymlopenapi diff --git a/.automation/test/openapi/openapi_good_2.json b/.automation/test/openapi/openapi_good_2.jsonopenapi similarity index 100% rename from .automation/test/openapi/openapi_good_2.json rename to .automation/test/openapi/openapi_good_2.jsonopenapi diff --git a/lib/linter.sh b/lib/linter.sh index 7b90ae32..b23b96e6 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2236,7 +2236,7 @@ RunTestCases() TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" - TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(yml\|yaml\|json\)\$" + TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$" ################# # Footer prints # From 79671724a0b0142b773e1387c5ddf75fef2f7638 Mon Sep 17 00:00:00 2001 From: Justin Kalland Date: Thu, 25 Jun 2020 12:21:11 +0200 Subject: [PATCH 3/6] Add OpenAPI to disabling-linters doc --- .github/linters/.openapirc.yml | 9 +++++++++ docs/disabling-linters.md | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .github/linters/.openapirc.yml diff --git a/.github/linters/.openapirc.yml b/.github/linters/.openapirc.yml new file mode 100644 index 00000000..fdf641e1 --- /dev/null +++ b/.github/linters/.openapirc.yml @@ -0,0 +1,9 @@ +--- + +########################## +########################## +## OpenAPI Linter rules ## +########################## +########################## + +extends: spectral:oas diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index c738bdbd..2f36d22d 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -24,6 +24,7 @@ Below are examples and documentation for each language and the various methods t - [CSS](#stylelint) - [ENV](#dotenv-linter) - [Kotlin](#kotlin) +- [OpenAPI](#openapi) @@ -607,3 +608,24 @@ import package.b.* ### ktlint disable entire file - There is currently **No** way to disable rules inline of the file(s) + +-------------------------------------------------------------------------------- + +## OpenAPI +- [spectral](https://github.com/stoplightio/spectral) + +### OpenAPI Config file +- `.github/linters/.openapirc.yml` +- You can add, extend, and disable rules +- Documentation at [Spectral Custom Rulesets](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/4-custom-rulesets.md) +- File should be located at: `.github/linters/.openapirc.yml` + +### OpenAPI disable single line +- There is currently **No** way to disable rules inline of the file(s) + +### OpenAPI disable code block +- There is currently **No** way to disable rules inline of the file(s) + +### OpenAPI disable entire file +- There is currently **No** way to disable rules inline of the file(s) +- However, you can make [rule exceptions](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/6-exceptions.md?srn=gh/stoplightio/spectral/docs/guides/6-exceptions.md) in the config for individual file(s). From 116698b03237fed27fa86ab9e4ebc1e4ac1266e0 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 26 Jun 2020 08:26:36 -0500 Subject: [PATCH 4/6] fixed linting errors --- lib/linter.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index a89bb3fe..06bc0022 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -573,10 +573,33 @@ LintAnsibleFiles() #### Function DetectOpenAPIFile ################################################ DetectOpenAPIFile() { - egrep '"openapi":|"swagger":|^openapi:|^swagger:' $GITHUB_WORKSPACE/$1 > /dev/null - if [ $? -eq 0 ]; then + ################ + # Pull in vars # + ################ + FILE="$1" + + ############################### + # Check the file for keywords # + ############################### + egrep '"openapi":|"swagger":|^openapi:|^swagger:' "$GITHUB_WORKSPACE/$FILE" > /dev/null + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -eq 0 ]; then + ######################## + # Found string in file # + ######################## return 0 else + ################### + # No string match # + ################### return 1 fi } @@ -1460,7 +1483,7 @@ BuildFileList() ############################ # Check if file is OpenAPI # ############################ - if DetectOpenAPIFile $FILE; then + if DetectOpenAPIFile "$FILE"; then FILE_ARRAY_OPENAPI+=("$FILE") fi ########################################################## @@ -1478,7 +1501,7 @@ BuildFileList() ############################ # Check if file is OpenAPI # ############################ - if DetectOpenAPIFile $FILE; then + if DetectOpenAPIFile "$FILE"; then FILE_ARRAY_OPENAPI+=("$FILE") fi ########################################################## @@ -2640,7 +2663,7 @@ if [ "$VALIDATE_OPENAPI" == "true" ]; then LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1)) for FILE in "${LIST_FILES[@]}" do - if DetectOpenAPIFile $FILE; then + if DetectOpenAPIFile "$FILE"; then FILE_ARRAY_OPENAPI+=("$FILE") fi done From 8fdce000bf0a0f18721d169b8dc79503c1c633bd Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 26 Jun 2020 08:44:27 -0500 Subject: [PATCH 5/6] got to catch them all --- lib/linter.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 06bc0022..ca352e6e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -581,7 +581,7 @@ DetectOpenAPIFile() ############################### # Check the file for keywords # ############################### - egrep '"openapi":|"swagger":|^openapi:|^swagger:' "$GITHUB_WORKSPACE/$FILE" > /dev/null + grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "$GITHUB_WORKSPACE/$FILE" > /dev/null ####################### # Load the error code # @@ -2232,7 +2232,7 @@ Footer() [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \ [ "$ERRORS_FOUND_CSS" -ne 0 ] || \ [ "$ERRORS_FOUND_ENV" -ne 0 ] || \ - [ "$ERRORS_FOUND_OPENAPI" -ne 0 ] \ + [ "$ERRORS_FOUND_OPENAPI" -ne 0 ] || \ [ "$ERRORS_FOUND_CLOJURE" -ne 0 ] || \ [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then # Failed exit @@ -2660,6 +2660,7 @@ fi if [ "$VALIDATE_OPENAPI" == "true" ]; then # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file if [ "$VALIDATE_ALL_CODEBASE" == "true" ]; then + # shellcheck disable=SC2207 LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1)) for FILE in "${LIST_FILES[@]}" do From f087775d99b15bf6632bbde557d17e18cab00d8b Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 26 Jun 2020 09:00:28 -0500 Subject: [PATCH 6/6] typo --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index ca352e6e..65b973a1 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -833,7 +833,7 @@ GetValidationInfo() -n "$VALIDATE_CSS" || \ -n "$VALIDATE_ENV" || \ -n "$VALIDATE_CLOJURE" || \ - -n "$VALIDATE_OPENAPI" ]] \ + -n "$VALIDATE_OPENAPI" || \ -n "$VALIDATE_KOTLIN" ]]; then ANY_SET="true" fi