Swetrix · API Governance Rules

Swetrix API Rules

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

9 Rules error 2 warn 6
View Rules File View on GitHub

Rule Categories

swetrix

Rules

warn
swetrix-api-key-header
Admin and Statistics API endpoints must use X-Api-Key security scheme
$.components.securitySchemes
warn
swetrix-operation-id-camel-case
Operation IDs must use camelCase naming convention
$.paths[*][get,post,put,patch,delete]
hint
swetrix-events-path-prefix
Events API paths should use /log prefix
$.paths
warn
swetrix-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
error
swetrix-post-request-body
POST operations must define a requestBody
$.paths[*].post
warn
swetrix-operation-tags
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
error
swetrix-pid-required
The pid parameter must be marked as required
$.paths[*][get,post,put,patch,delete].parameters[?(@.name == 'pid')]
warn
swetrix-error-responses
Mutating operations should document 400 error responses
$.paths[*][post,put,patch].responses
warn
swetrix-success-response-content
Success responses (200/201) should define content schema
$.paths[*][get,post,put,patch].responses[200,201]

Spectral Ruleset

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

rules:
  # Swetrix uses X-Api-Key header authentication for admin/statistics APIs
  swetrix-api-key-header:
    description: Admin and Statistics API endpoints must use X-Api-Key security scheme
    severity: warn
    given: "$.components.securitySchemes"
    then:
      field: ApiKeyAuth
      function: truthy

  # All operation IDs must use camelCase
  swetrix-operation-id-camel-case:
    description: Operation IDs must use camelCase naming convention
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"

  # Events API uses /log prefix for all paths
  swetrix-events-path-prefix:
    description: Events API paths should use /log prefix
    severity: hint
    given: "$.paths"
    then:
      function: schema
      functionOptions:
        schema:
          type: object

  # All operations must have summaries in Title Case
  swetrix-summary-title-case:
    description: Operation summaries must use Title Case
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][A-Za-z0-9 ]+$"

  # Request bodies for POST operations must be defined
  swetrix-post-request-body:
    description: POST operations must define a requestBody
    severity: error
    given: "$.paths[*].post"
    then:
      field: requestBody
      function: truthy

  # Tags must be defined at operation level
  swetrix-operation-tags:
    description: All operations must have at least one tag
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  # pid parameter must be required when present
  swetrix-pid-required:
    description: The pid parameter must be marked as required
    severity: error
    given: "$.paths[*][get,post,put,patch,delete].parameters[?(@.name == 'pid')]"
    then:
      field: required
      function: truthy

  # Responses must include 400 for POST/PUT/PATCH
  swetrix-error-responses:
    description: Mutating operations should document 400 error responses
    severity: warn
    given: "$.paths[*][post,put,patch].responses"
    then:
      field: '400'
      function: truthy

  # Successful responses must have content defined
  swetrix-success-response-content:
    description: Success responses (200/201) should define content schema
    severity: warn
    given: "$.paths[*][get,post,put,patch].responses[200,201]"
    then:
      field: content
      function: truthy