Travelers · API Governance Rules

Travelers API Rules

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

11 Rules error 2 warn 7
View Rules File View on GitHub

Rule Categories

travelers

Rules

warn
travelers-operation-summary-title-case
All operation summaries must use Title Case
$.paths[*][*].summary
error
travelers-operationid-required
All operations must have an operationId
$.paths[*][*]
warn
travelers-tags-required
All operations must have tags
$.paths[*][*]
warn
travelers-oauth2-required
Insurance API should use OAuth2 authentication
$.components.securitySchemes[*]
error
travelers-response-200-get
GET operations must have a 200 response
$.paths[*].get.responses
warn
travelers-response-201-post
POST operations that create resources should return 201
$.paths[*].post.responses
hint
travelers-claim-number-in-path
Claim endpoints should use claim_number as path parameter
$.paths['/claims/{claim_number}'][*].parameters[*][?(@.name=='id')]
warn
travelers-policy-type-enum
Policy types should be validated against known types
$.components.schemas[*].properties.policy_type
warn
travelers-date-format
Date fields should use ISO 8601 date format
$.components.schemas[*].properties[?(@.format=='date')]
warn
travelers-data-wrapper
Responses should wrap content in a data property
$.components.schemas[?(@property.match(/Response$/))].properties
hint
travelers-amount-format
Monetary amount fields should use number format float
$.components.schemas[*].properties[?(@.property.match(/amount|premium|incurred/i))]

Spectral Ruleset

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

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

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

  travelers-oauth2-required:
    description: Insurance API should use OAuth2 authentication
    severity: warn
    given: "$.components.securitySchemes[*]"
    then:
      field: type
      function: enumeration
      functionOptions:
        values:
          - oauth2
          - http

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

  travelers-response-201-post:
    description: POST operations that create resources should return 201
    severity: warn
    given: "$.paths[*].post.responses"
    then:
      field: "201"
      function: truthy

  travelers-claim-number-in-path:
    description: Claim endpoints should use claim_number as path parameter
    severity: hint
    given: "$.paths['/claims/{claim_number}'][*].parameters[*][?(@.name=='id')]"
    then:
      function: falsy

  travelers-policy-type-enum:
    description: Policy types should be validated against known types
    severity: warn
    given: "$.components.schemas[*].properties.policy_type"
    then:
      field: enum
      function: truthy

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

  travelers-data-wrapper:
    description: Responses should wrap content in a data property
    severity: warn
    given: "$.components.schemas[?(@property.match(/Response$/))].properties"
    then:
      field: data
      function: truthy

  travelers-amount-format:
    description: Monetary amount fields should use number format float
    severity: hint
    given: "$.components.schemas[*].properties[?(@.property.match(/amount|premium|incurred/i))]"
    then:
      field: format
      function: enumeration
      functionOptions:
        values:
          - float
          - double