HaveIBeenPwned · API Governance Rules

HaveIBeenPwned API Rules

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

12 Rules error 5 warn 7
View Rules File View on GitHub

Rule Categories

hibp

Rules

error
hibp-operation-summary-required
Every operation MUST have a summary string using Title Case.
$.paths[*][get,post,put,patch,delete]
warn
hibp-operation-description-required
Every operation MUST have a description.
$.paths[*][get,post,put,patch,delete]
error
hibp-operation-id-required
Every operation MUST declare an operationId.
$.paths[*][get,post,put,patch,delete]
warn
hibp-operation-tag-required
Every operation MUST be tagged exactly once.
$.paths[*][get,post,put,patch,delete]
error
hibp-api-key-security-scheme
HIBP authenticated endpoints MUST use the hibp-api-key header security scheme.
$.components.securitySchemes.ApiKeyAuth
warn
hibp-user-agent-documented
The info.description SHOULD remind clients of the mandatory user-agent header.
$.info.description
warn
hibp-401-on-authenticated-paths
Authenticated endpoints SHOULD document a 401 response.
$.paths[?(@property != '/breaches' && @property != '/dataclasses' && @property != '/latestbreach' && @property.indexOf('/breach/') < 0)][get,post,put,patch,delete].responses
warn
hibp-429-rate-limit-response
Authenticated endpoints SHOULD document a 429 Too Many Requests response.
$.paths[*][get].responses
warn
hibp-pascal-case-schemas
Schema names MUST be PascalCase.
$.components.schemas[*]~
warn
hibp-path-lowercase
HIBP path segments MUST be lowercase (the API is case-insensitive but canonical form is lowercase).
$.paths[*]~
error
hibp-contact-required
info.contact MUST be present and include a URL.
$.info.contact
error
hibp-license-required
HIBP API MUST be tagged with the CC 4.0 license.
$.info.license

Spectral Ruleset

Raw ↑
extends: [[spectral:oas, all]]
documentationUrl: https://haveibeenpwned.com/API/v3
formats:
  - oas3
rules:
  # Operations
  hibp-operation-summary-required:
    description: Every operation MUST have a summary string using Title Case.
    given: $.paths[*][get,post,put,patch,delete]
    severity: error
    then:
      field: summary
      function: truthy

  hibp-operation-description-required:
    description: Every operation MUST have a description.
    given: $.paths[*][get,post,put,patch,delete]
    severity: warn
    then:
      field: description
      function: truthy

  hibp-operation-id-required:
    description: Every operation MUST declare an operationId.
    given: $.paths[*][get,post,put,patch,delete]
    severity: error
    then:
      field: operationId
      function: truthy

  hibp-operation-tag-required:
    description: Every operation MUST be tagged exactly once.
    given: $.paths[*][get,post,put,patch,delete]
    severity: warn
    then:
      field: tags
      function: length
      functionOptions:
        min: 1
        max: 1

  # Authentication conventions
  hibp-api-key-security-scheme:
    description: HIBP authenticated endpoints MUST use the hibp-api-key header security scheme.
    given: $.components.securitySchemes.ApiKeyAuth
    severity: error
    then:
      - field: type
        function: pattern
        functionOptions: { match: '^apiKey$' }
      - field: in
        function: pattern
        functionOptions: { match: '^header$' }
      - field: name
        function: pattern
        functionOptions: { match: '^hibp-api-key$' }

  # User-Agent requirement
  hibp-user-agent-documented:
    description: The info.description SHOULD remind clients of the mandatory user-agent header.
    given: $.info.description
    severity: warn
    then:
      function: pattern
      functionOptions: { match: 'user-agent' }

  # Response coverage
  hibp-401-on-authenticated-paths:
    description: Authenticated endpoints SHOULD document a 401 response.
    given: $.paths[?(@property != '/breaches' && @property != '/dataclasses' && @property != '/latestbreach' && @property.indexOf('/breach/') < 0)][get,post,put,patch,delete].responses
    severity: warn
    then:
      field: '401'
      function: truthy

  hibp-429-rate-limit-response:
    description: Authenticated endpoints SHOULD document a 429 Too Many Requests response.
    given: $.paths[*][get].responses
    severity: warn
    then:
      field: '429'
      function: truthy

  # Naming
  hibp-pascal-case-schemas:
    description: Schema names MUST be PascalCase.
    given: $.components.schemas[*]~
    severity: warn
    then:
      function: pattern
      functionOptions: { match: '^[A-Z][A-Za-z0-9]+$' }

  # Path conventions
  hibp-path-lowercase:
    description: HIBP path segments MUST be lowercase (the API is case-insensitive but canonical form is lowercase).
    given: $.paths[*]~
    severity: warn
    then:
      function: pattern
      functionOptions: { match: '^/[a-z0-9{}/_.-]+$' }

  # Cross-cutting
  hibp-contact-required:
    description: info.contact MUST be present and include a URL.
    given: $.info.contact
    severity: error
    then:
      - field: name
        function: truthy
      - field: url
        function: truthy

  hibp-license-required:
    description: HIBP API MUST be tagged with the CC 4.0 license.
    given: $.info.license
    severity: error
    then:
      - field: name
        function: truthy
      - field: url
        function: truthy