TransportAPI · API Governance Rules

TransportAPI API Rules

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

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

Rule Categories

transportapi

Rules

warn
transportapi-operation-summary-title-case
All operation summaries must use Title Case
$.paths[*][*].summary
error
transportapi-operationid-required
All operations must have an operationId
$.paths[*][*]
warn
transportapi-tags-required
All operations must have tags
$.paths[*][*]
hint
transportapi-json-extension-in-paths
UK transport endpoints should end with .json extension
$.paths
error
transportapi-response-200-required
All GET operations must have a 200 response
$.paths[*].get.responses
warn
transportapi-app-auth-params
API authentication via app_id and app_key query parameters must be documented
$.components.securitySchemes
info
transportapi-uk-base-path
All paths should operate under UK data context
$.servers[*].url
hint
transportapi-atcocode-path-param
Bus stop path parameters should be named atcocode
$.paths[*][*].parameters[*][?(@.in=='path' && @.name=='station_stop')]
warn
transportapi-datetime-format
Date-time properties should use ISO 8601 format
$.components.schemas[*].properties[?(@.format=='date-time')]
hint
transportapi-pagination-limit
Collection endpoints should support limit parameter
$.paths[*].get.parameters[*][?(@.name=='limit')]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  transportapi-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]*)*$"

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

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

  transportapi-json-extension-in-paths:
    description: UK transport endpoints should end with .json extension
    severity: hint
    given: "$.paths"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          patternProperties:
            ".*\\.json$": {}

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

  transportapi-app-auth-params:
    description: API authentication via app_id and app_key query parameters must be documented
    severity: warn
    given: "$.components.securitySchemes"
    then:
      function: truthy

  transportapi-uk-base-path:
    description: All paths should operate under UK data context
    severity: info
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: ".*transportapi\\.com.*"

  transportapi-atcocode-path-param:
    description: Bus stop path parameters should be named atcocode
    severity: hint
    given: "$.paths[*][*].parameters[*][?(@.in=='path' && @.name=='station_stop')]"
    then:
      function: falsy

  transportapi-datetime-format:
    description: Date-time properties should use ISO 8601 format
    severity: warn
    given: "$.components.schemas[*].properties[?(@.format=='date-time')]"
    then:
      field: format
      function: enumeration
      functionOptions:
        values:
          - date-time

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