name: Validate OpenAPI schema with Spectral
on:
  workflow_call: { }
  pull_request:
    branches: ['2.6.x']
    paths:
      - common/src/main/resources/META-INF/openapi.json

jobs:
  validate:
    name: Validate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install RHOAS Guidelines linter
        run: |
          npm i @rhoas/spectral-ruleset
          echo 'extends: "@rhoas/spectral-ruleset"' > .spectral.yaml
      - name: Validate OpenAPI schema with Spectral and RHOAS Guidelines (Common)
        run: npx rhoasapi lint common/src/main/resources/META-INF/openapi.json
      - name: Validate OpenAPI schema with Spectral and RHOAS Guidelines (Final)
        run: npx rhoasapi lint app/src/main/resources-unfiltered/META-INF/resources/api-specifications/registry/v2/openapi.json
      - name: Cleanup
        run: |
          rm .spectral.yaml
