From 29bd8893c69a0b6418fe64958440e48d7294963d Mon Sep 17 00:00:00 2001 From: Colin Loretz Date: Tue, 15 Jul 2025 14:41:09 -0700 Subject: [PATCH] Added spectral github action --- .github/workflows/spectral-lint.yml | 52 +++++++++++++++++++++++++++++ .spectral.yml | 31 +++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/spectral-lint.yml create mode 100644 .spectral.yml diff --git a/.github/workflows/spectral-lint.yml b/.github/workflows/spectral-lint.yml new file mode 100644 index 0000000..b3d5301 --- /dev/null +++ b/.github/workflows/spectral-lint.yml @@ -0,0 +1,52 @@ +name: API Spec Linting + +on: + push: + paths: + - 'specs/**' + - '.spectral.yml' + pull_request: + paths: + - 'specs/**' + - '.spectral.yml' + workflow_dispatch: + +jobs: + spectral-lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install Spectral CLI + run: npm install -g @stoplight/spectral-cli + + - name: Lint OpenAPI specs + run: | + echo "Linting OpenAPI specifications with Spectral..." + echo "Using configuration: .spectral.yml" + + echo "::group::Linting openapi.json" + spectral lint specs/openapi.json --format stylish --verbose + echo "::endgroup::" + + echo "::group::Linting openapi_preview.json" + spectral lint specs/openapi_preview.json --format stylish --verbose + echo "::endgroup::" + + echo "✅ All specs linted successfully!" + + - name: Upload lint results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: spectral-lint-results + path: | + specs/ + retention-days: 7 \ No newline at end of file diff --git a/.spectral.yml b/.spectral.yml new file mode 100644 index 0000000..f73e478 --- /dev/null +++ b/.spectral.yml @@ -0,0 +1,31 @@ +extends: ["spectral:oas"] + +rules: + # OpenAPI-specific rules + openapi-tags: true + operation-description: true + operation-operationId: true + operation-operationId-unique: true + operation-operationId-valid-in-url: true + operation-parameters: true + operation-success-response: true + operation-tag-defined: true + path-keys-no-trailing-slash: true + path-not-include-query: true + + # Schema rules + typed-enum: true + no-$ref-siblings: true + + # Info rules + # info-contact: true + # info-description: true + # info-license: true + + # require-example-for-schemas: + # description: "All schemas should have examples" + # given: "$.components.schemas[*]" + # then: + # field: example + # function: truthy + # severity: warn \ No newline at end of file