WHMCS · API Governance Rules

WHMCS API Rules

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

10 Rules error 5 warn 5
View Rules File View on GitHub

Rule Categories

whmcs

Rules

error
whmcs-path-must-include-action
All WHMCS API paths must include an ?action= query parameter identifying the operation.
$.paths[*]~
warn
whmcs-operation-id-camel-case
WHMCS operation IDs must use camelCase to match the API command naming convention.
$.paths[*][*].operationId
error
whmcs-post-only
All WHMCS API operations must use POST method. WHMCS does not support GET, PUT, or DELETE.
$.paths[*]
error
whmcs-auth-required
All WHMCS API operations must reference the AuthCredentials schema for authentication.
$.paths[*].post.requestBody.content['application/x-www-form-urlencoded'].schema
warn
whmcs-response-json
WHMCS API responses must support application/json content type.
$.paths[*].post.responses[*].content
warn
whmcs-operation-summary-required
All WHMCS API operations must have a summary in Title Case.
$.paths[*].post.summary
warn
whmcs-operation-tags-required
All WHMCS API operations must have at least one tag for categorization.
$.paths[*].post.tags
error
whmcs-request-form-urlencoded
WHMCS API request bodies must use application/x-www-form-urlencoded content type.
$.paths[*].post.requestBody.content
warn
whmcs-response-result-field
All WHMCS API responses must include a 'result' field indicating success or error.
$.components.schemas[*].properties
error
whmcs-info-version-required
WHMCS API spec must include a version in the info object.
$.info.version

Spectral Ruleset

Raw ↑
extends: "spectral:oas"

rules:
  # WHMCS uses POST with ?action= query param for all operations
  whmcs-path-must-include-action:
    description: All WHMCS API paths must include an ?action= query parameter identifying the operation.
    severity: error
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^\\?action=[A-Za-z]+"

  # Operation IDs must use camelCase
  whmcs-operation-id-camel-case:
    description: WHMCS operation IDs must use camelCase to match the API command naming convention.
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"

  # All operations must use POST (WHMCS is POST-only)
  whmcs-post-only:
    description: All WHMCS API operations must use POST method. WHMCS does not support GET, PUT, or DELETE.
    severity: error
    given: "$.paths[*]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          required:
            - post
          not:
            anyOf:
              - required: [get]
              - required: [put]
              - required: [delete]
              - required: [patch]

  # All operations must have authentication credentials in request body
  whmcs-auth-required:
    description: All WHMCS API operations must reference the AuthCredentials schema for authentication.
    severity: error
    given: "$.paths[*].post.requestBody.content['application/x-www-form-urlencoded'].schema"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            allOf:
              type: array

  # Responses must use application/json
  whmcs-response-json:
    description: WHMCS API responses must support application/json content type.
    severity: warn
    given: "$.paths[*].post.responses[*].content"
    then:
      function: truthy

  # Operations must have summaries
  whmcs-operation-summary-required:
    description: All WHMCS API operations must have a summary in Title Case.
    severity: warn
    given: "$.paths[*].post.summary"
    then:
      function: truthy

  # All operations must be tagged
  whmcs-operation-tags-required:
    description: All WHMCS API operations must have at least one tag for categorization.
    severity: warn
    given: "$.paths[*].post.tags"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          minItems: 1

  # RequestBody must be form-urlencoded
  whmcs-request-form-urlencoded:
    description: WHMCS API request bodies must use application/x-www-form-urlencoded content type.
    severity: error
    given: "$.paths[*].post.requestBody.content"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          required:
            - "application/x-www-form-urlencoded"

  # All response schemas must include a 'result' field
  whmcs-response-result-field:
    description: All WHMCS API responses must include a 'result' field indicating success or error.
    severity: warn
    given: "$.components.schemas[*].properties"
    then:
      function: truthy

  # API version must be documented
  whmcs-info-version-required:
    description: WHMCS API spec must include a version in the info object.
    severity: error
    given: "$.info.version"
    then:
      function: truthy