Senior LevelREST APIs & Web Services
How do you enforce API Governance across teams using Spectral OpenAPI Linters in CI/CD?
❓ Interview Prompt: Explain API Governance, automated linting with Stoplight Spectral, enforcing URI casing, error contract standards, and breaking build rules in CI/CD.
As engineering organizations grow to dozens of teams, enforcing consistent API design conventions requires automated API Governance in CI/CD pipelines using Spectral:
Custom Spectral Linter Rules:
•
Enforce camelCase query params and kebab-case URIs.
•
Require '401', '403', and '500' error response definitions on every path.
•
Block non-HTTPS server URLs and enforce RFC 7807 error structures.
•
Fail CI/CD build pull requests if API specs violate governance rules!
Code Implementation Example
yaml
# .spectral.yaml - Organizational API Governance Ruleset
extends: "spectral:oas"
rules:
paths-kebab-case:
description: "ALL URI path segments must be kebab-case"
given: "$.paths[*]~"
then:
function: pattern
functionOptions:
match: "^/([a-z0-9-]+|{[a-zA-Z0-9_]+})*$"
rfc7807-error-schema:
description: "Error responses MUST use application/problem+json"
given: "$.paths..responses[?(@property >= 400)].content"
then:
field: "application/problem+json"
function: defined💡Spectral linter ruleset enforcing kebab-case paths and RFC 7807 error contracts in CI/CD.
🎯 Interview Key Takeaway
Use Spectral in CI/CD to enforce automated API governance rules across all OpenAPI specifications.
#API Governance#Spectral#OpenAPI#Linter#Senior
Back to all REST APIs & Web Services Questions→