API Snap · API Governance Rules

API Snap API Rules

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

42 Rules error 11 warn 23 info 8
View Rules File View on GitHub

Rule Categories

error examples get info microcks no openapi operation parameter paths post query request response schema security servers tags

Rules

error
info-title-required
Spec must declare an info.title.
$.info
warn
info-description-required
Spec must declare an info.description with at least 60 characters.
$.info
error
info-version-required
Spec must declare info.version.
$.info
warn
info-contact-required
Spec must declare info.contact with name and url.
$.info.contact
warn
openapi-version-3-0-3
API Snap uses OpenAPI 3.0.3.
$.openapi
error
servers-defined
At least one server must be defined.
$
error
servers-https
All servers must use HTTPS.
$.servers[*].url
info
servers-api-snap
Production server should be https://api-snap.com.
$.servers[*].url
error
paths-api-prefix
All paths must be prefixed with /api/.
$.paths
warn
paths-kebab-case
Path segments must be lowercase kebab-case (e.g. /api/jwt-decode).
$.paths
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths
error
operation-summary-required
Every operation must have a summary in Title Case.
$.paths[*][get,post,put,patch,delete]
warn
operation-description-required
Every operation should have a description.
$.paths[*][get,post,put,patch,delete]
error
operation-id-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete]
warn
operation-id-camel-case
operationId must be camelCase (e.g. generateQrCode, captureScreenshot).
$.paths[*][get,post,put,patch,delete].operationId
info
operation-id-verb-prefix
operationId should start with a recognized verb (generate, capture, convert, hash, resize, decode, extract, base64).
$.paths[*][get,post,put,patch,delete].operationId
warn
operation-tags-required
Every operation must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
tags-pascal-case
Tags must use PascalCase (e.g. Images, Browser, Documents, Security, Utilities).
$.paths[*][get,post,put,patch,delete].tags[*]
info
tags-from-allowed-set
Tags should be one of the documented categories.
$.paths[*][get,post,put,patch,delete].tags[*]
warn
parameter-description-required
Every parameter must have a description.
$.paths[*][get,post,put,patch,delete].parameters[*]
info
parameter-snake-case
Query parameters use snake_case (full_page) when multi-word.
$.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')].name
info
parameter-api-key-allowed
api_key query parameter is permitted as an Authorization header alias.
$.paths[*][get,post,put,patch,delete].parameters[?(@.name=='api_key')]
error
request-body-content-required
Request bodies must declare a content map.
$.paths[*][post,put,patch].requestBody
warn
request-body-json-or-multipart
Request bodies should use application/json or multipart/form-data.
$.paths[*][post,put,patch].requestBody.content
error
response-200-required
Every operation must declare a 200 success response.
$.paths[*][get,post,put,patch,delete].responses
warn
response-401-required
Every operation must declare a 401 response (missing/invalid API key).
$.paths[*][get,post,put,patch,delete].responses
warn
response-429-required
Every operation must declare a 429 response (rate limit exceeded).
$.paths[*][get,post,put,patch,delete].responses
warn
response-description-required
Each response must have a description.
$.paths[*][get,post,put,patch,delete].responses[*]
info
schema-camel-case-properties
JSON body and response properties use camelCase (urlSafe, expiresAt).
$.components.schemas[*].properties
warn
schema-type-required
Schema properties must declare a type or $ref.
$.components.schemas[*].properties[*]
error
security-schemes-defined
components.securitySchemes must define at least one scheme.
$.components
warn
security-bearer-auth
BearerAuth security scheme must be defined for the snp_ API key.
$.components.securitySchemes
warn
security-global-required
Top-level security must be declared and reference BearerAuth.
$
error
get-no-request-body
GET operations must not declare a requestBody.
$.paths[*].get
warn
post-has-request-body
POST operations should declare a requestBody.
$.paths[*].post
info
examples-encouraged
Operations should include at least one example for response or request.
$.paths[*][get,post,put,patch,delete].responses[*].content[*]
info
microcks-extension-encouraged
Operations should include x-microcks-operation for mock-server compatibility.
$.paths[*][get,post,put,patch,delete]
warn
servers-expected-domain
Server URLs should be on the api-snap.com domain.
$.servers[*].url
warn
query-params-casing
Query parameters should be snake_case (the dominant convention in this API).
$.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')]
warn
error-schema-defined
A shared error schema (Error) should be defined for error payloads.
$.components.schemas
warn
operation-documents-400
Operations should document a 400 response (documented on 86% of this API's operations).
$.paths[*][get,post,put,patch,delete].responses
warn
no-empty-descriptions
Descriptions must not be empty strings.
$..description

Spectral Ruleset

Raw ↑
# api-snap — Spectral ruleset (strengthened)
# Plain Spectral. Existing hand-authored rules preserved; measured rules added
# from this provider's own OpenAPI conventions by strengthen_ruleset.py,
# then self-validated against the spec.
#
# Provenance:
#   - servers-https-only: 100% of servers already https (error)
#   - servers-expected-domain: 1/1 servers on api-snap.com
#   - query-params-casing: snake @ 100% (n=26)
#   - operationid-casing: camel @ 100% (n=14)
#   - security: global (root) — NOT emitting operation-security-required
#   - error-schema-defined: Error
#   - operation-documents-400: 86% adherence
#   - operation-documents-401: 100% adherence
#   - operation-documents-429: 100% adherence
#   - pagination params observed: ['count', 'size']
#   - merge: kept 37 existing, added 5 measured, upgraded 0
#   - added: servers-expected-domain, query-params-casing, error-schema-defined, operation-documents-400, no-empty-descriptions
extends:
  - spectral:oas
rules:
  info-title-required:
    description: Spec must declare an info.title.
    given: $.info
    severity: error
    then:
      field: title
      function: truthy
  info-description-required:
    description: Spec must declare an info.description with at least 60 characters.
    given: $.info
    severity: warn
    then:
      field: description
      function: length
      functionOptions:
        min: 60
  info-version-required:
    description: Spec must declare info.version.
    given: $.info
    severity: error
    then:
      field: version
      function: truthy
  info-contact-required:
    description: Spec must declare info.contact with name and url.
    given: $.info.contact
    severity: warn
    then:
    - field: name
      function: truthy
    - field: url
      function: truthy
  openapi-version-3-0-3:
    description: API Snap uses OpenAPI 3.0.3.
    given: $.openapi
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: ^3\.0\.\d+$
  servers-defined:
    description: At least one server must be defined.
    given: $
    severity: error
    then:
      field: servers
      function: truthy
  servers-https:
    description: All servers must use HTTPS.
    given: $.servers[*].url
    severity: error
    then:
      function: pattern
      functionOptions:
        match: ^https://
  servers-api-snap:
    description: Production server should be https://api-snap.com.
    given: $.servers[*].url
    severity: info
    then:
      function: pattern
      functionOptions:
        match: ^https://api-snap\.com
  paths-api-prefix:
    description: All paths must be prefixed with /api/.
    given: $.paths
    severity: error
    then:
      field: '@key'
      function: pattern
      functionOptions:
        match: ^/api/
  paths-kebab-case:
    description: Path segments must be lowercase kebab-case (e.g. /api/jwt-decode).
    given: $.paths
    severity: warn
    then:
      field: '@key'
      function: pattern
      functionOptions:
        match: ^/[a-z0-9/-]+$
  paths-no-trailing-slash:
    description: Paths must not end with a trailing slash.
    given: $.paths
    severity: warn
    then:
      field: '@key'
      function: pattern
      functionOptions:
        notMatch: .+/$
  operation-summary-required:
    description: Every operation must have a summary in Title Case.
    given: $.paths[*][get,post,put,patch,delete]
    severity: error
    then:
      field: summary
      function: truthy
  operation-description-required:
    description: Every operation should have a description.
    given: $.paths[*][get,post,put,patch,delete]
    severity: warn
    then:
      field: description
      function: truthy
  operation-id-required:
    description: Every operation must have an operationId.
    given: $.paths[*][get,post,put,patch,delete]
    severity: error
    then:
      field: operationId
      function: truthy
  operation-id-camel-case:
    description: operationId must be camelCase (e.g. generateQrCode, captureScreenshot).
    given: $.paths[*][get,post,put,patch,delete].operationId
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: ^[a-z][a-zA-Z0-9]+$
  operation-id-verb-prefix:
    description: operationId should start with a recognized verb (generate, capture, convert, hash, resize,
      decode, extract, base64).
    given: $.paths[*][get,post,put,patch,delete].operationId
    severity: info
    then:
      function: pattern
      functionOptions:
        match: ^(generate|capture|convert|hash|resize|decode|extract|base64|html|markdown)
  operation-tags-required:
    description: Every operation must declare at least one tag.
    given: $.paths[*][get,post,put,patch,delete]
    severity: warn
    then:
      field: tags
      function: length
      functionOptions:
        min: 1
  tags-pascal-case:
    description: Tags must use PascalCase (e.g. Images, Browser, Documents, Security, Utilities).
    given: $.paths[*][get,post,put,patch,delete].tags[*]
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: ^[A-Z][a-zA-Z]+$
  tags-from-allowed-set:
    description: Tags should be one of the documented categories.
    given: $.paths[*][get,post,put,patch,delete].tags[*]
    severity: info
    then:
      function: enumeration
      functionOptions:
        values:
        - Images
        - Browser
        - Documents
        - Security
        - Utilities
  parameter-description-required:
    description: Every parameter must have a description.
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    severity: warn
    then:
      field: description
      function: truthy
  parameter-snake-case:
    description: Query parameters use snake_case (full_page) when multi-word.
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')].name
    severity: info
    then:
      function: pattern
      functionOptions:
        match: ^[a-z][a-z0-9_]*$
  parameter-api-key-allowed:
    description: api_key query parameter is permitted as an Authorization header alias.
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.name=='api_key')]
    severity: info
    then:
      function: truthy
  request-body-content-required:
    description: Request bodies must declare a content map.
    given: $.paths[*][post,put,patch].requestBody
    severity: error
    then:
      field: content
      function: truthy
  request-body-json-or-multipart:
    description: Request bodies should use application/json or multipart/form-data.
    given: $.paths[*][post,put,patch].requestBody.content
    severity: warn
    then:
      field: '@key'
      function: pattern
      functionOptions:
        match: ^(application/json|multipart/form-data)$
  response-200-required:
    description: Every operation must declare a 200 success response.
    given: $.paths[*][get,post,put,patch,delete].responses
    severity: error
    then:
      field: '200'
      function: truthy
  response-401-required:
    description: Every operation must declare a 401 response (missing/invalid API key).
    given: $.paths[*][get,post,put,patch,delete].responses
    severity: warn
    then:
      field: '401'
      function: truthy
  response-429-required:
    description: Every operation must declare a 429 response (rate limit exceeded).
    given: $.paths[*][get,post,put,patch,delete].responses
    severity: warn
    then:
      field: '429'
      function: truthy
  response-description-required:
    description: Each response must have a description.
    given: $.paths[*][get,post,put,patch,delete].responses[*]
    severity: warn
    then:
      field: description
      function: truthy
  schema-camel-case-properties:
    description: JSON body and response properties use camelCase (urlSafe, expiresAt).
    given: $.components.schemas[*].properties
    severity: info
    then:
      field: '@key'
      function: pattern
      functionOptions:
        match: ^[a-z][a-zA-Z0-9]*$
  schema-type-required:
    description: Schema properties must declare a type or $ref.
    given: $.components.schemas[*].properties[*]
    severity: warn
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
          - required:
            - type
          - required:
            - $ref
          - required:
            - oneOf
          - required:
            - anyOf
          - required:
            - allOf
  security-schemes-defined:
    description: components.securitySchemes must define at least one scheme.
    given: $.components
    severity: error
    then:
      field: securitySchemes
      function: truthy
  security-bearer-auth:
    description: BearerAuth security scheme must be defined for the snp_ API key.
    given: $.components.securitySchemes
    severity: warn
    then:
      field: BearerAuth
      function: truthy
  security-global-required:
    description: Top-level security must be declared and reference BearerAuth.
    given: $
    severity: warn
    then:
      field: security
      function: truthy
  get-no-request-body:
    description: GET operations must not declare a requestBody.
    given: $.paths[*].get
    severity: error
    then:
      field: requestBody
      function: falsy
  post-has-request-body:
    description: POST operations should declare a requestBody.
    given: $.paths[*].post
    severity: warn
    then:
      field: requestBody
      function: truthy
  examples-encouraged:
    description: Operations should include at least one example for response or request.
    given: $.paths[*][get,post,put,patch,delete].responses[*].content[*]
    severity: info
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
          - required:
            - example
          - required:
            - examples
  microcks-extension-encouraged:
    description: Operations should include x-microcks-operation for mock-server compatibility.
    given: $.paths[*][get,post,put,patch,delete]
    severity: info
    then:
      field: x-microcks-operation
      function: truthy
  servers-expected-domain:
    description: Server URLs should be on the api-snap.com domain.
    severity: warn
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: api\-snap\.com
  query-params-casing:
    description: Query parameters should be snake_case (the dominant convention in this API).
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')]
    then:
      field: name
      function: casing
      functionOptions:
        type: snake
  error-schema-defined:
    description: A shared error schema (Error) should be defined for error payloads.
    severity: warn
    given: $.components.schemas
    then:
      field: Error
      function: truthy
  operation-documents-400:
    description: Operations should document a 400 response (documented on 86% of this API's operations).
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      field: '400'
      function: truthy
  no-empty-descriptions:
    description: Descriptions must not be empty strings.
    severity: warn
    given: $..description
    then:
      function: truthy