Swell · API Governance Rules

Swell API Rules

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

7 Rules error 3 warn 3 info 1
View Rules File View on GitHub

Rule Categories

swell

Rules

error
swell-operation-tag-required
Every operation MUST have at least one tag.
$.paths.*[get,post,put,patch,delete]
error
swell-operation-id-camel
operationId MUST be lowerCamelCase.
$.paths.*[get,post,put,patch,delete].operationId
warn
swell-summary-title-case
Operation summaries MUST be in Title Case.
$.paths.*[get,post,put,patch,delete].summary
warn
swell-resource-id-pattern
Path parameter ids should be 24-char hex ObjectIds.
$.paths..parameters[?(@.name=='id' && @.in=='path')].schema.pattern
warn
swell-money-fields-number
Money fields MUST be type number.
$.components.schemas.*.properties[grand_total,sub_total,tax_total,shipment_total,discount_total,price,sale_price,amount,balance,recurring_total].type
info
swell-list-responses-pagination
List responses SHOULD include count, page, results.
$.components.schemas[?(@property.match(/List$/))].properties
error
swell-security-required
Every operation MUST require security.
$.paths.*[get,post,put,patch,delete]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  swell-operation-tag-required:
    description: Every operation MUST have at least one tag.
    given: $.paths.*[get,post,put,patch,delete]
    severity: error
    then:
      field: tags
      function: truthy

  swell-operation-id-camel:
    description: operationId MUST be lowerCamelCase.
    given: $.paths.*[get,post,put,patch,delete].operationId
    severity: error
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"

  swell-summary-title-case:
    description: Operation summaries MUST be in Title Case.
    given: $.paths.*[get,post,put,patch,delete].summary
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^([A-Z][A-Za-z0-9-]*)(\\s([A-Z][A-Za-z0-9-]*|[a-z]{1,3}))*$"

  swell-resource-id-pattern:
    description: Path parameter ids should be 24-char hex ObjectIds.
    given: $.paths..parameters[?(@.name=='id' && @.in=='path')].schema.pattern
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "[a-f0-9]"

  swell-money-fields-number:
    description: Money fields MUST be type number.
    given: $.components.schemas.*.properties[grand_total,sub_total,tax_total,shipment_total,discount_total,price,sale_price,amount,balance,recurring_total].type
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^number$"

  swell-list-responses-pagination:
    description: List responses SHOULD include count, page, results.
    given: $.components.schemas[?(@property.match(/List$/))].properties
    severity: info
    then:
      function: truthy

  swell-security-required:
    description: Every operation MUST require security.
    given: $.paths.*[get,post,put,patch,delete]
    severity: error
    then:
      field: security
      function: defined