QA
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→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?