MobileAPI.dev · API Governance Rules

MobileAPI.dev API Rules

Spectral linting rules defining API design standards and conventions for MobileAPI.dev.

11 Rules error 3 warn 4 info 4
View Rules File View on GitHub

Rule Categories

mobileapi

Rules

error
mobileapi-operation-summary-required
Every operation must have a summary.
$.paths.*[get,post,put,patch,delete]
warn
mobileapi-operation-summary-title-case
Operation summaries should be in Title Case (first word capitalized, no trailing period).
$.paths.*[get,post,put,patch,delete].summary
warn
mobileapi-tags-lowercase-hyphen
Tags should be lowercase, hyphen-separated.
$.paths.*[get,post,put,patch,delete].tags[*]
error
mobileapi-operation-id-required
Every operation must declare an operationId.
$.paths.*[get,post,put,patch,delete]
warn
mobileapi-path-trailing-slash
Paths should end with a trailing slash (Django convention).
$.paths
warn
mobileapi-success-response-required
Every operation should declare a 2xx success response.
$.paths.*[get,post,put,patch,delete].responses
info
mobileapi-unauthorized-response-documented
Authenticated operations should document a 401 response.
$.paths[?(@property != '/api-token-auth/' && @property != '/status/' && @property != '/payment_successful' && @property != '/payment_successful/')]*[get,post,put,patch,delete].responses
info
mobileapi-rate-limit-response-documented
Operations that consume credits should document a 429 Too Many Requests response.
$.paths[?(@property != '/api-token-auth/' && @property != '/status/')]*[get,post,put,patch,delete].responses
info
mobileapi-schema-id-property
Resource schemas should include an 'id' property as primary key.
$.components.schemas[?(@.type == 'object')]
info
mobileapi-prefer-header-auth
Document Authorization header as primary auth, query parameter as fallback only.
$.components.securitySchemes
error
mobileapi-https-server
Production server URL must use HTTPS.
$.servers[*].url

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas
rules:
  # MobileAPI.dev: every operation must declare a summary in Title Case.
  mobileapi-operation-summary-required:
    description: Every operation must have a summary.
    given: "$.paths.*[get,post,put,patch,delete]"
    severity: error
    then:
      field: summary
      function: truthy

  mobileapi-operation-summary-title-case:
    description: Operation summaries should be in Title Case (first word capitalized, no trailing period).
    given: "$.paths.*[get,post,put,patch,delete].summary"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z\\[].*[^\\.]$"

  # MobileAPI.dev: tags must use lowercase-hyphenated form (Django REST Framework default).
  mobileapi-tags-lowercase-hyphen:
    description: Tags should be lowercase, hyphen-separated.
    given: "$.paths.*[get,post,put,patch,delete].tags[*]"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[a-z0-9][a-z0-9\\-]*$"

  # MobileAPI.dev: every operation must declare an operationId for client codegen.
  mobileapi-operation-id-required:
    description: Every operation must declare an operationId.
    given: "$.paths.*[get,post,put,patch,delete]"
    severity: error
    then:
      field: operationId
      function: truthy

  # MobileAPI.dev: paths use a trailing slash (Django REST Framework convention).
  mobileapi-path-trailing-slash:
    description: Paths should end with a trailing slash (Django convention).
    given: "$.paths"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "/$"
      field: "@key"

  # MobileAPI.dev: every operation should declare a 200/201 response.
  mobileapi-success-response-required:
    description: Every operation should declare a 2xx success response.
    given: "$.paths.*[get,post,put,patch,delete].responses"
    severity: warn
    then:
      function: truthy
      field: "200"

  # MobileAPI.dev: every operation should document a 401 Unauthorized response.
  mobileapi-unauthorized-response-documented:
    description: Authenticated operations should document a 401 response.
    given: "$.paths[?(@property != '/api-token-auth/' && @property != '/status/' && @property != '/payment_successful' && @property != '/payment_successful/')]*[get,post,put,patch,delete].responses"
    severity: info
    then:
      function: truthy
      field: "401"

  # MobileAPI.dev: rate-limited operations should document 429 responses.
  mobileapi-rate-limit-response-documented:
    description: Operations that consume credits should document a 429 Too Many Requests response.
    given: "$.paths[?(@property != '/api-token-auth/' && @property != '/status/')]*[get,post,put,patch,delete].responses"
    severity: info
    then:
      function: truthy
      field: "429"

  # MobileAPI.dev: schemas should include id and human-readable name where applicable.
  mobileapi-schema-id-property:
    description: Resource schemas should include an 'id' property as primary key.
    given: "$.components.schemas[?(@.type == 'object')]"
    severity: info
    then:
      field: properties.id
      function: truthy

  # MobileAPI.dev: prefer ApiKeyHeader (Authorization) over ApiKeyQuery for production traffic.
  mobileapi-prefer-header-auth:
    description: Document Authorization header as primary auth, query parameter as fallback only.
    given: "$.components.securitySchemes"
    severity: info
    then:
      field: ApiKeyHeader
      function: truthy

  # MobileAPI.dev: server URL should be HTTPS only in production.
  mobileapi-https-server:
    description: Production server URL must use HTTPS.
    given: "$.servers[*].url"
    severity: error
    then:
      function: pattern
      functionOptions:
        match: "^https://"