Bored API · API Governance Rules

Bored API API Rules

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

12 Rules error 8 warn 4
View Rules File View on GitHub

Rule Categories

bored

Rules

error
bored-info-contact
API contact information must be present.
$.info
error
bored-info-license
API license information must be present (project is MIT).
$.info
error
bored-https-public-server
Public Bored API servers must use HTTPS.
$.servers[?(@.url && @.url.indexOf('boredapi.com') > -1)].url
error
bored-appbrewery-https
App Brewery mirror server must use HTTPS.
$.servers[?(@.url && @.url.indexOf('appbrewery.com') > -1)].url
error
bored-operation-id
Every operation must declare a unique operationId.
$.paths[*][get,post,put,patch,delete]
warn
bored-operation-summary-title-case
Operation summaries should be in Title Case.
$.paths[*][get,post,put,patch,delete].summary
warn
bored-operation-tag
Every operation must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
bored-activity-type-enum
Activity type enum must use the canonical Bored API categories.
$.components.schemas[?(@property=='ActivityV1' || @property=='ActivityV2' || @property=='Activity')].properties.type.enum
error
bored-v2-accessibility-enum
V2 accessibility must use the canonical three-level enum.
$.components.schemas.ActivityV2.properties.accessibility.enum
error
bored-key-string
Resource key fields must be strings (not integers).
$.components.schemas[?(@property=='ActivityV1' || @property=='ActivityV2' || @property=='Activity' || @property=='Fact' || @property=='Riddle' || @property=='Website')].properties.key.type
error
bored-riddle-difficulty-enum
Riddle difficulty must use the canonical easy/normal/hard enum.
$.components.schemas.Riddle.properties.difficulty.enum
warn
bored-no-auth-required
Bored API must not require authentication on any operation.
$.paths[*][get,post,put,patch,delete]

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

# Spectral linting rules for the Bored API surface.
# These rules capture the conventions of the canonical Drew Thoennes
# Bored-API project (github.com/drewthoennes/Bored-API) plus the
# App Brewery community fork, encoding the cross-cutting style of the
# API: HTTPS-only public endpoints, mandatory operationId, plain GET
# endpoints, JSON-only responses, and stable enum values for type,
# accessibility, duration, and difficulty.
rules:
  bored-info-contact:
    description: API contact information must be present.
    severity: error
    given: "$.info"
    then:
      field: contact
      function: truthy

  bored-info-license:
    description: API license information must be present (project is MIT).
    severity: error
    given: "$.info"
    then:
      field: license
      function: truthy

  bored-https-public-server:
    description: Public Bored API servers must use HTTPS.
    severity: error
    given: "$.servers[?(@.url && @.url.indexOf('boredapi.com') > -1)].url"
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  bored-appbrewery-https:
    description: App Brewery mirror server must use HTTPS.
    severity: error
    given: "$.servers[?(@.url && @.url.indexOf('appbrewery.com') > -1)].url"
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  bored-operation-id:
    description: Every operation must declare a unique operationId.
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  bored-operation-summary-title-case:
    description: Operation summaries should be in Title Case.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  bored-operation-tag:
    description: Every operation must declare at least one tag.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  bored-activity-type-enum:
    description: Activity type enum must use the canonical Bored API categories.
    severity: warn
    given: "$.components.schemas[?(@property=='ActivityV1' || @property=='ActivityV2' || @property=='Activity')].properties.type.enum"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum:
              - charity
              - cooking
              - music
              - diy
              - education
              - social
              - busywork
              - recreational
              - relaxation

  bored-v2-accessibility-enum:
    description: V2 accessibility must use the canonical three-level enum.
    severity: error
    given: "$.components.schemas.ActivityV2.properties.accessibility.enum"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum:
              - Few to no challenges
              - Minor challenges
              - Major challenges

  bored-key-string:
    description: Resource key fields must be strings (not integers).
    severity: error
    given: "$.components.schemas[?(@property=='ActivityV1' || @property=='ActivityV2' || @property=='Activity' || @property=='Fact' || @property=='Riddle' || @property=='Website')].properties.key.type"
    then:
      function: pattern
      functionOptions:
        match: "^string$"

  bored-riddle-difficulty-enum:
    description: Riddle difficulty must use the canonical easy/normal/hard enum.
    severity: error
    given: "$.components.schemas.Riddle.properties.difficulty.enum"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum:
              - easy
              - normal
              - hard

  bored-no-auth-required:
    description: Bored API must not require authentication on any operation.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: security
      function: falsy