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

Work with this as data

Every ruleset here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for spectral rules

4 MCP tools reach this
  • find_rulesBrowse and filter every ruleset in the catalog.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This ruleset
curl "https://apis.io/api/v1/rules/trefle-rules"
All spectral rules
curl "https://apis.io/api/v1/rules?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.