-
Notifications
You must be signed in to change notification settings - Fork 3
Add GitHub automation openapi linters #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds GitHub Actions automation and configuration for OpenAPI specification linting using Spectral. A new workflow triggers on repository pushes and pull requests affecting the specs directory, installing Spectral and executing lint checks with verbose output. A Spectral configuration file extends the base OpenAPI ruleset while disabling the oas3-valid-media-example rule for non-JSON media types. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
.github/workflows/openapi-lint.yml (2)
22-28: Consider adding npm caching for faster workflow runs.The Node.js setup is correct, but adding cache configuration could speed up subsequent workflow runs.
🔎 Optional improvement to add npm caching
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' + cache: 'npm'Note: This requires a
package.jsonorpackage-lock.jsonfile in the repository root. If these don't exist, you can skip this optimization or use a different caching strategy.
30-31: Consider using npx instead of global installation.While global installation works fine, using
npxcan simplify the workflow by avoiding the installation step altogether. This is a minor stylistic suggestion.🔎 Alternative approach using npx
- - name: Install Spectral - run: npm install -g @stoplight/spectral-cli - - name: Lint OpenAPI Specs - run: spectral lint "specs/*.openapi.yml" --verbose + run: npx @stoplight/spectral-cli lint "specs/*.openapi.yml" --verboseThis approach automatically downloads and runs the latest compatible version without requiring a separate installation step.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/openapi-lint.yml.spectral.yaml
🔇 Additional comments (3)
.github/workflows/openapi-lint.yml (2)
3-15: LGTM: Well-configured workflow triggers.The trigger configuration is well thought out, running only when relevant paths change (specs, workflow file, or Spectral config). This prevents unnecessary workflow runs and saves CI resources.
30-34: The glob pattern"specs/*.openapi.yml"correctly matches all OpenAPI spec files in this repository. The specs directory contains only top-level files with no subdirectories, so the current pattern is sufficient and no changes are needed.Likely an incorrect or invalid review comment.
.spectral.yaml (1)
1-7: Disabling the rule entirely is the correct approach for this use case.The configuration is appropriate. Spectral's oas3-valid-media-example rule struggles with non-JSON media types like application/xml, and Spectral does not provide built-in options to exclude specific media types from validation. Attempting a more targeted approach would require creating a custom rule rather than modifying the built-in rule, which is more complex than the current solution.
Motivation
As we add OpenAPI specs to this repository, we need to ensure they are properly validated. This PR adds automated linting to catch issues early.
Solution
.spectral.yamlwith the standard OpenAPI rulesetoas3-valid-media-examplerule to avoid false positives with JSON Lines (application/jsonl) format, which Spectral doesn't natively supportChanges
.github/workflows/openapi-lint.yml- GitHub Action that runs on push/PR tomain/masterbranches.spectral.yaml- Spectral configuration fileHow to Test
Run locally:
npx @stoplight/spectral-cli lint "specs/*.openapi.yml"also check https://github.com/mailtrap/mailtrap-openapi/actions
Expected output: 0 errors, a few non-critical warnings (unused components, missing servers array).
The GitHub Action will automatically run on every push/PR to validate all OpenAPI specs in the
specs/directory.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.