Sound Transit · API Governance Rules

Sound Transit API Rules

Spectral linting rules defining API design standards and conventions for Sound Transit.

10 Rules error 2 warn 7 info 1
View Rules File View on GitHub

Rule Categories

sound

Rules

error
sound-transit-api-key-required
All Sound Transit API operations require the 'key' query parameter
$.paths[*][get].parameters[?(@.name == 'key')]
warn
sound-transit-json-suffix
Sound Transit OneBusAway API paths use .json suffix
$.paths
warn
sound-transit-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
error
sound-transit-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
sound-transit-operation-id-camel-case
OperationId must use camelCase convention
$.paths[*][get,post,put,patch,delete].operationId
warn
sound-transit-operation-has-tags
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
warn
sound-transit-401-response
Operations must document 401 Unauthorized for invalid API key
$.paths[*][get,post,put,patch,delete].responses
warn
sound-transit-response-schema-defined
Successful responses must have a schema
$.paths[*][get].responses['200'].content['application/json']
warn
sound-transit-tags-title-case
All tags in the spec must use Title Case
$.tags[*].name
info
sound-transit-base-response-structure
All response schemas should reference BaseResponse or include code and currentTime fields
$.components.schemas.BaseResponse

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Sound Transit OneBusAway API always requires API key query parameter
  sound-transit-api-key-required:
    description: All Sound Transit API operations require the 'key' query parameter
    severity: error
    given: "$.paths[*][get].parameters[?(@.name == 'key')]"
    then:
      field: required
      function: truthy

  # All paths use .json suffix - enforce this pattern
  sound-transit-json-suffix:
    description: Sound Transit OneBusAway API paths use .json suffix
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: ".*\\.json$"

  # All operations must have summaries in Title Case
  sound-transit-operation-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]*([ ][A-Z][a-zA-Z0-9]*)*$"

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

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

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

  # 401 response for missing API key
  sound-transit-401-response:
    description: Operations must document 401 Unauthorized for invalid API key
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "401"
      function: defined

  # Response schemas must be defined
  sound-transit-response-schema-defined:
    description: Successful responses must have a schema
    severity: warn
    given: "$.paths[*][get].responses['200'].content['application/json']"
    then:
      field: schema
      function: defined

  # All tags must be Title Case
  sound-transit-tags-title-case:
    description: All tags in the spec must use Title Case
    severity: warn
    given: "$.tags[*].name"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9]*([ ][A-Z][a-zA-Z0-9]*)*$"

  # BaseResponse structure - all responses inherit from BaseResponse
  sound-transit-base-response-structure:
    description: All response schemas should reference BaseResponse or include code and currentTime fields
    severity: info
    given: "$.components.schemas.BaseResponse"
    then:
      field: properties
      function: truthy