Unleash · API Governance Rules

Unleash API Rules

Spectral linting rules defining API design standards and conventions for Unleash.

8 Rules error 1 warn 4 info 3
View Rules File View on GitHub

Rule Categories

unleash

Rules

info
unleash-admin-path-prefix
Admin API paths must start with /api/admin/
$.paths[*]~
warn
unleash-title-case-summary
Operation summaries must use Title Case
$.paths[*][*].summary
warn
unleash-operation-tags
All operations must have at least one tag
$.paths[*][*]
error
unleash-operation-id
All operations must have an operationId
$.paths[*][*]
info
unleash-auth-header
Admin API operations must require Authorization header
$.paths[/api/admin*][*]
info
unleash-feature-project-scope
Feature flag paths should be scoped under /projects/{projectId}/
$.paths[/api/admin/features*]~
warn
unleash-not-found-response
Resource endpoints should define 404 responses
$.paths[*][get,delete,put,patch]
warn
unleash-unauthorized-response
Protected operations should define 401 responses
$.paths[/api/admin*][*]

Spectral Ruleset

Raw ↑
extends: [[spectral:oas, all]]

rules:

  # Unleash Admin API paths use kebab-case prefixed with /api/admin/
  unleash-admin-path-prefix:
    description: Admin API paths must start with /api/admin/
    message: "Path '{{path}}' should be prefixed with /api/admin/"
    severity: info
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^/api/(admin|client|frontend)"

  # Operation summaries must be Title Case
  unleash-title-case-summary:
    description: Operation summaries must use Title Case
    message: "Summary '{{value}}' should use Title Case"
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  # Operations must have tags for grouping
  unleash-operation-tags:
    description: All operations must have at least one tag
    message: "{{description}}: {{path}}"
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  # All operations must have operationIds
  unleash-operation-id:
    description: All operations must have an operationId
    message: "Operation at {{path}} missing operationId"
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  # Authorization header for admin API operations
  unleash-auth-header:
    description: Admin API operations must require Authorization header
    message: "Admin operation may require Authorization header parameter"
    severity: info
    given: "$.paths[/api/admin*][*]"
    then:
      field: security
      function: defined

  # Features paths use project-scoped routes
  unleash-feature-project-scope:
    description: Feature flag paths should be scoped under /projects/{projectId}/
    message: "Feature path should be scoped: /api/admin/projects/{projectId}/features"
    severity: info
    given: "$.paths[/api/admin/features*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "^/api/admin/features"

  # 404 responses for resource paths
  unleash-not-found-response:
    description: Resource endpoints should define 404 responses
    message: "Missing 404 response for resource operation"
    severity: warn
    given: "$.paths[*][get,delete,put,patch]"
    then:
      field: "responses.404"
      function: defined

  # 401 for unauthenticated requests
  unleash-unauthorized-response:
    description: Protected operations should define 401 responses
    message: "Protected operation should define 401 response"
    severity: warn
    given: "$.paths[/api/admin*][*]"
    then:
      field: "responses.401"
      function: defined