Twilio · API Governance Rules

Twilio API Rules

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

12 Rules error 2 warn 8
View Rules File View on GitHub

Rule Categories

twilio

Rules

warn
twilio-summary-prefix
All operation summaries must start with "Twilio "
$.paths[*][get,post,put,patch,delete].summary
warn
twilio-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
warn
twilio-security-scheme
Operations must reference an accountSid_authToken security scheme
$.security
hint
twilio-json-suffix-paths
Twilio REST API paths should end with .json for list and single resources
$.paths[?([email protected](/\.json$/) && [email protected](/\{[^}]+\}$/))]
warn
twilio-tags-title-case
All tags must use Title Case
$.tags[*].name
warn
twilio-operation-id-camel-case
Operation IDs must use camelCase
$.paths[*][get,post,put,patch,delete].operationId
error
twilio-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
twilio-operation-description-required
All operations must have a description
$.paths[*][get,post,put,patch,delete]
warn
twilio-operation-tags-required
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
hint
twilio-form-encoded-bodies
POST/PUT request bodies should prefer application/x-www-form-urlencoded
$.paths[*][post,put].requestBody.content
warn
twilio-contact-info
API info must include contact information
$.info
error
twilio-servers-defined
At least one server must be defined
$

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

rules:
  # Twilio uses "Twilio " prefix in all operation summaries
  twilio-summary-prefix:
    description: All operation summaries must start with "Twilio "
    message: "Summary '{{value}}' must begin with 'Twilio '"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^Twilio "

  # Twilio uses Title Case for summaries
  twilio-summary-title-case:
    description: Operation summaries must use Title Case
    message: "Summary '{{value}}' should use Title Case"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  # Twilio always uses Basic auth with AccountSid:AuthToken
  twilio-security-scheme:
    description: Operations must reference an accountSid_authToken security scheme
    severity: warn
    given: "$.security"
    then:
      field: accountSid_authToken
      function: defined

  # Twilio uses .json suffix on resource paths for REST API
  twilio-json-suffix-paths:
    description: Twilio REST API paths should end with .json for list and single resources
    message: "Path '{{path}}' should end with .json"
    severity: hint
    given: "$.paths[?([email protected](/\\.json$/) && [email protected](/\\{[^}]+\\}$/))]"
    then:
      function: truthy

  # All tags must use Title Case
  twilio-tags-title-case:
    description: All tags must use Title Case
    message: "Tag '{{value}}' must use Title Case"
    severity: warn
    given: "$.tags[*].name"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  # All operationIds must be camelCase
  twilio-operation-id-camel-case:
    description: Operation IDs must use camelCase
    message: "OperationId '{{value}}' must use camelCase"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  # Require operationId on all operations
  twilio-operation-id-required:
    description: All operations must have an operationId
    message: "Operation at {{path}} must have an operationId"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: defined

  # Require description on all operations
  twilio-operation-description-required:
    description: All operations must have a description
    message: "Operation at {{path}} must have a description"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: description
      function: defined

  # Require tags on all operations
  twilio-operation-tags-required:
    description: All operations must have at least one tag
    message: "Operation at {{path}} must specify at least one tag"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: defined

  # Twilio uses form-encoded bodies for POST/PUT
  twilio-form-encoded-bodies:
    description: POST/PUT request bodies should prefer application/x-www-form-urlencoded
    severity: hint
    given: "$.paths[*][post,put].requestBody.content"
    then:
      field: "application/x-www-form-urlencoded"
      function: defined

  # Require contact info
  twilio-contact-info:
    description: API info must include contact information
    severity: warn
    given: "$.info"
    then:
      field: contact
      function: defined

  # Require servers
  twilio-servers-defined:
    description: At least one server must be defined
    severity: error
    given: "$"
    then:
      field: servers
      function: defined