Trefle · API Governance Rules

Trefle API Rules

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

9 Rules error 3 warn 5 info 1
View Rules File View on GitHub

Rule Categories

trefle

Rules

error
trefle-operation-id-required
All Trefle API operations should have an operationId.
$.paths[*][get,post,put,patch,delete]
warn
trefle-token-auth-documented
The Trefle API uses token-based authentication. The global security scheme should specify the tokenAuth apiKey scheme.
$
error
trefle-response-200-defined
All Trefle API GET operations should define a 200 response.
$.paths[*].get.responses
warn
trefle-response-401-defined
All operations should document 401 Unauthorized for token auth errors.
$.paths[*][get,post,put,patch,delete].responses
warn
trefle-response-404-on-id-paths
Endpoints with path parameters (individual resource lookups) should document the 404 Not Found response.
$.paths[*{id}*][get].responses
warn
trefle-tags-required
All operations should have at least one tag for navigation.
$.paths[*][*].tags
warn
trefle-description-required
All operations should have a description.
$.paths[*][*]
error
trefle-summary-required
All operations should have a summary.
$.paths[*][*]
info
trefle-pagination-links
List operations (returning arrays) should include pagination links in the 200 response, consistent with the Trefle API data/links/meta structure.
$.paths[*].get.responses.200

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  trefle-operation-id-required:
    description: All Trefle API operations should have an operationId.
    message: "Operation should have an operationId"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  trefle-token-auth-documented:
    description: >-
      The Trefle API uses token-based authentication. The global security
      scheme should specify the tokenAuth apiKey scheme.
    message: "API should declare global security with token authentication"
    severity: warn
    given: "$"
    then:
      field: security
      function: truthy

  trefle-response-200-defined:
    description: All Trefle API GET operations should define a 200 response.
    message: "GET operation should define a 200 response"
    severity: error
    given: "$.paths[*].get.responses"
    then:
      function: schema
      functionOptions:
        schema:
          required: ["200"]

  trefle-response-401-defined:
    description: All operations should document 401 Unauthorized for token auth errors.
    message: "Operation should define a 401 Unauthorized response"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      function: schema
      functionOptions:
        schema:
          required: ["401"]

  trefle-response-404-on-id-paths:
    description: >-
      Endpoints with path parameters (individual resource lookups) should
      document the 404 Not Found response.
    message: "ID-based lookup should define a 404 Not Found response"
    severity: warn
    given: "$.paths[*{id}*][get].responses"
    then:
      function: schema
      functionOptions:
        schema:
          required: ["404"]

  trefle-tags-required:
    description: All operations should have at least one tag for navigation.
    message: "Operation should have at least one tag"
    severity: warn
    given: "$.paths[*][*].tags"
    then:
      function: length
      functionOptions:
        min: 1

  trefle-description-required:
    description: All operations should have a description.
    message: "Operation should have a description"
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: description
      function: truthy

  trefle-summary-required:
    description: All operations should have a summary.
    message: "Operation should have a summary"
    severity: error
    given: "$.paths[*][*]"
    then:
      field: summary
      function: truthy

  trefle-pagination-links:
    description: >-
      List operations (returning arrays) should include pagination links in
      the 200 response, consistent with the Trefle API data/links/meta structure.
    message: "List operation should include pagination links in response schema"
    severity: info
    given: "$.paths[*].get.responses.200"
    then:
      function: schema
      functionOptions:
        schema:
          type: object