Transit · API Governance Rules

Transit API Rules

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

Transit API Rules is a Spectral governance ruleset published by Transit on the APIs.io network, containing 9 lint rules.

The ruleset includes 2 error-severity rules, 5 warning-severity rules, and 2 hint-severity rules.

Tagged areas include Public Transit, Real-Time, Trip Planning, Multimodal, and GTFS.

Rulesets can be applied to your own OpenAPI specs via Spectral to enforce the same governance standards.

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

Rule Categories

transit

Rules

warn
transit-operation-summary-title-case
All operation summaries must use Title Case
$.paths[*][*].summary
error
transit-operationid-required
All operations must have an operationId
$.paths[*][*]
warn
transit-operationid-kebab-case
OperationIds should use camelCase
$.paths[*][*].operationId
warn
transit-tags-required
All operations must have tags
$.paths[*][*]
warn
transit-coordinates-lat-lon
Latitude and longitude parameters should be named lat and lon
$.paths[*][*].parameters[*].name
error
transit-response-200-required
All GET operations must have a 200 response
$.paths[*].get.responses
warn
transit-api-key-auth
API must use apiKey authentication
$.components.securitySchemes[*]
hint
transit-stop-codes-plural
Stop code query parameters should use plural form stop_codes
$.paths[*][*].parameters[*][?(@.in=='query' && @.name=='stop_code')]
hint
transit-pagination-limit-param
Collection endpoints should support limit parameter for pagination
$.paths[*].get.parameters[*][?(@.name=='max_departures' || @.name=='limit')]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  transit-operation-summary-title-case:
    description: All operation summaries must use Title Case
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z]*(\\s[A-Z][a-zA-Z]*)*$"

  transit-operationid-required:
    description: All operations must have an operationId
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  transit-operationid-kebab-case:
    description: OperationIds should use camelCase
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  transit-tags-required:
    description: All operations must have tags
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  transit-coordinates-lat-lon:
    description: Latitude and longitude parameters should be named lat and lon
    severity: warn
    given: "$.paths[*][*].parameters[*].name"
    then:
      function: pattern
      functionOptions:
        notMatch: "^(latitude|longitude|lng|long)$"

  transit-response-200-required:
    description: All GET operations must have a 200 response
    severity: error
    given: "$.paths[*].get.responses"
    then:
      field: "200"
      function: truthy

  transit-api-key-auth:
    description: API must use apiKey authentication
    severity: warn
    given: "$.components.securitySchemes[*]"
    then:
      field: type
      function: enumeration
      functionOptions:
        values:
          - apiKey
          - http
          - oauth2

  transit-stop-codes-plural:
    description: Stop code query parameters should use plural form stop_codes
    severity: hint
    given: "$.paths[*][*].parameters[*][?(@.in=='query' && @.name=='stop_code')]"
    then:
      function: falsy

  transit-pagination-limit-param:
    description: Collection endpoints should support limit parameter for pagination
    severity: hint
    given: "$.paths[*].get.parameters[*][?(@.name=='max_departures' || @.name=='limit')]"
    then:
      field: schema
      function: truthy