Sorry · API Governance Rules

Sorry API Rules

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

12 Rules error 3 warn 7 info 2
View Rules File View on GitHub

Rule Categories

sorry

Rules

info
sorry-nested-resource-pattern
Sorry API uses /pages/{page_id}/... nested resource pattern
$.paths
warn
sorry-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
error
sorry-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
sorry-operation-id-camel-case
OperationId must use camelCase convention
$.paths[*][get,post,put,patch,delete].operationId
warn
sorry-operation-has-tags
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
error
sorry-post-has-request-body
POST and PATCH operations must define a requestBody
$.paths[*][post,patch]
warn
sorry-401-response
All operations must document a 401 Unauthorized response
$.paths[*][get,post,put,patch,delete].responses
warn
sorry-delete-returns-204
DELETE operations should return 204 No Content
$.paths[*].delete.responses
warn
sorry-tags-title-case
All tags in the spec must use Title Case
$.tags[*].name
info
sorry-rate-limit-documented
API info should mention rate limiting (10 req/s)
$.info
error
sorry-security-defined
Bearer auth security must be defined
$
warn
sorry-response-schema-defined
Successful responses must define a JSON schema
$.paths[*][get,post,patch].responses['200','201'].content['application/json']

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Sorry API uses nested resource paths - enforce consistent pattern
  sorry-nested-resource-pattern:
    description: Sorry API uses /pages/{page_id}/... nested resource pattern
    severity: info
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^/pages(/.*)?$"

  # All operations must have summaries in Title Case
  sorry-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
  sorry-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
  sorry-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
  sorry-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

  # POST operations must have requestBody
  sorry-post-has-request-body:
    description: POST and PATCH operations must define a requestBody
    severity: error
    given: "$.paths[*][post,patch]"
    then:
      field: requestBody
      function: truthy

  # Must document 401 response
  sorry-401-response:
    description: All operations must document a 401 Unauthorized response
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "401"
      function: defined

  # DELETE operations should return 204
  sorry-delete-returns-204:
    description: DELETE operations should return 204 No Content
    severity: warn
    given: "$.paths[*].delete.responses"
    then:
      field: "204"
      function: defined

  # All tags must be Title Case
  sorry-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]*)*$"

  # Rate limiting documentation
  sorry-rate-limit-documented:
    description: API info should mention rate limiting (10 req/s)
    severity: info
    given: "$.info"
    then:
      field: description
      function: truthy

  # Security must be defined
  sorry-security-defined:
    description: Bearer auth security must be defined
    severity: error
    given: "$"
    then:
      field: security
      function: defined

  # Response schemas for successful responses
  sorry-response-schema-defined:
    description: Successful responses must define a JSON schema
    severity: warn
    given: "$.paths[*][get,post,patch].responses['200','201'].content['application/json']"
    then:
      field: schema
      function: defined