Scrapfly · API Governance Rules

Scrapfly API Rules

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

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

Rule Categories

scrapfly

Rules

error
scrapfly-api-key-query-param
All operations must include the API key query parameter
$.paths[*][get,post].parameters
error
scrapfly-url-param-required
Scrape endpoints must include the 'url' parameter
$.paths['/scrape'][get,post].parameters
error
scrapfly-operation-ids
All operations must have operationId
$.paths[*][*]
warn
scrapfly-tags-required
All operations must have at least one tag
$.paths[*][*]
info
scrapfly-response-credit-headers
Scrape responses should document credit consumption headers
$.paths['/scrape'].get.responses['200']
warn
scrapfly-boolean-default-values
Boolean parameters should have explicit default values
$.paths[*][*].parameters[?(@.schema.type === 'boolean')]
warn
scrapfly-error-responses
Operations should document error responses
$.paths[*][*].responses
warn
scrapfly-parameter-descriptions
Parameters should have descriptions
$.paths[*][*].parameters[*]
warn
scrapfly-camel-case-operation-ids
Operation IDs should use camelCase
$.paths[*][*].operationId

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

rules:
  scrapfly-api-key-query-param:
    description: All operations must include the API key query parameter
    message: "Scrapfly operations must include 'key' query parameter for authentication"
    severity: error
    given: "$.paths[*][get,post].parameters"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          contains:
            type: object
            properties:
              name:
                const: key
              in:
                const: query

  scrapfly-url-param-required:
    description: Scrape endpoints must include the 'url' parameter
    message: "Scraping operations must require the 'url' query parameter"
    severity: error
    given: "$.paths['/scrape'][get,post].parameters"
    then:
      function: truthy

  scrapfly-operation-ids:
    description: All operations must have operationId
    message: "Every operation must have a unique operationId"
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  scrapfly-tags-required:
    description: All operations must have at least one tag
    message: "Operations must be tagged for categorization"
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  scrapfly-response-credit-headers:
    description: Scrape responses should document credit consumption headers
    message: "Scrape responses should document X-Scrapfly-Api-Cost and related headers"
    severity: info
    given: "$.paths['/scrape'].get.responses['200']"
    then:
      field: headers
      function: truthy

  scrapfly-boolean-default-values:
    description: Boolean parameters should have explicit default values
    message: "Boolean parameters like render_js and asp should have explicit default values"
    severity: warn
    given: "$.paths[*][*].parameters[?(@.schema.type === 'boolean')]"
    then:
      field: schema.default
      function: defined

  scrapfly-error-responses:
    description: Operations should document error responses
    message: "Operations should document at least 401 and 429 error responses"
    severity: warn
    given: "$.paths[*][*].responses"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          required:
            - '401'

  scrapfly-parameter-descriptions:
    description: Parameters should have descriptions
    message: "Parameter '{{value}}' should have a description"
    severity: warn
    given: "$.paths[*][*].parameters[*]"
    then:
      field: description
      function: truthy

  scrapfly-camel-case-operation-ids:
    description: Operation IDs should use camelCase
    message: "OperationId '{{value}}' should use camelCase naming"
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"