Toornament · API Governance Rules

Toornament API Rules

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

9 Rules error 3 warn 5
View Rules File View on GitHub

Rule Categories

toornament

Rules

warn
toornament-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
error
toornament-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
toornament-operation-description-required
All operations must have a description
$.paths[*][get,post,put,patch,delete]
error
toornament-api-key-required
API key security should be defined
$.components.securitySchemes
error
toornament-oauth2-required
OAuth2 security should be defined for write operations
$.components.securitySchemes
warn
toornament-pagination-range-header
List endpoints (GET /tournaments etc.) should document Range header
$.paths[*].get.parameters[?(@.name == 'Range')]
hint
toornament-list-response-206
Paginated list endpoints should return 206 Partial Content
$.paths[*].get.responses
warn
toornament-path-param-description
Path parameters should have descriptions
$.paths[*][*].parameters[?(@.in=='path')]
warn
toornament-delete-no-content
DELETE operations should return 204 No Content
$.paths[*].delete.responses

Spectral Ruleset

Raw ↑
extends: spectral:oas

rules:
  # Toornament API uses Title Case operation summaries
  toornament-operation-summary-title-case:
    description: Operation summaries must use Title Case
    message: "Operation summary '{{value}}' should use Title Case"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z ]+$"

  # All operations must have operationId
  toornament-operation-id-required:
    description: All operations must have an operationId
    message: "Operation is missing an operationId"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  # All operations must have a description
  toornament-operation-description-required:
    description: All operations must have a description
    message: "Operation is missing a description"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: description
      function: truthy

  # Tournament endpoints must require X-Api-Key header
  toornament-api-key-required:
    description: API key security should be defined
    message: "X-Api-Key security scheme should be defined"
    severity: error
    given: "$.components.securitySchemes"
    then:
      field: apiKey
      function: truthy

  # OAuth2 security scheme should be defined
  toornament-oauth2-required:
    description: OAuth2 security should be defined for write operations
    message: "OAuth2 security scheme should be defined"
    severity: error
    given: "$.components.securitySchemes"
    then:
      field: oauth2
      function: truthy

  # Paginated list endpoints should accept Range header
  toornament-pagination-range-header:
    description: List endpoints (GET /tournaments etc.) should document Range header
    message: "Paginated GET endpoints should accept a Range header parameter"
    severity: warn
    given: "$.paths[*].get.parameters[?(@.name == 'Range')]"
    then:
      field: in
      function: enumeration
      functionOptions:
        values:
          - header

  # Successful list responses should return 206 Partial Content
  toornament-list-response-206:
    description: Paginated list endpoints should return 206 Partial Content
    message: "Paginated list endpoint should return 206, not 200"
    severity: hint
    given: "$.paths[*].get.responses"
    then:
      field: "206"
      function: truthy

  # Path parameters should be described
  toornament-path-param-description:
    description: Path parameters should have descriptions
    message: "Path parameter '{{value}}' is missing a description"
    severity: warn
    given: "$.paths[*][*].parameters[?(@.in=='path')]"
    then:
      field: description
      function: truthy

  # DELETE operations should return 204
  toornament-delete-no-content:
    description: DELETE operations should return 204 No Content
    message: "DELETE operation should include a 204 response"
    severity: warn
    given: "$.paths[*].delete.responses"
    then:
      field: "204"
      function: truthy