Better Stack · API Governance Rules

Better Stack API Rules

Spectral linting rules defining API design standards and conventions for Better Stack.

43 Rules error 13 warn 23 info 7
View Rules File View on GitHub

Rule Categories

error examples http info no openapi operation parameter path paths query request response schema security servers tags

Rules

warn
info-title-prefix
API title should start with "Better Stack"
$.info.title
error
info-description-required
API info must have a description
$.info
warn
info-description-min-length
API description should be at least 30 characters
$.info.description
error
info-version-required
API info must specify a version
$.info
warn
openapi-version
OpenAPI version should be 3.0.x
$.openapi
error
servers-defined
At least one server must be defined
$
error
servers-https-only
All server URLs must use HTTPS
$.servers[*].url
warn
servers-description-required
Each server should have a description
$.servers[*]
warn
paths-kebab-case
Path segments should use kebab-case
$.paths
error
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths
error
paths-no-query-string
Query strings must not appear in paths
$.paths
error
operation-summary-required
All operations must have a summary
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-summary-title-case
Operation summaries should start with "Better Stack"
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
All operations must have a description
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-id-camel-case
operationId should use camelCase
$.paths[*][get,post,put,patch,delete].operationId
warn
operation-tags-required
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete,head,options]
info
tags-global-defined
Global tags array should be defined
$
info
tags-description-required
Each global tag should have a description
$.tags[*]
warn
parameter-description-required
All parameters must have a description
$.paths[*][get,post,put,patch,delete].parameters[*]
error
parameter-schema-required
All parameters must have a schema
$.paths[*][get,post,put,patch,delete].parameters[*]
info
parameter-snake-case
Query parameter names should use snake_case
$.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')].name
warn
request-body-json-content
Request bodies should use application/json content type
$.paths[*][post,put,patch].requestBody.content
error
response-success-required
Every operation must define a 2xx success response
$.paths[*][get,post,put,patch,delete].responses
info
response-401-defined
Operations should define a 401 Unauthorized response
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
All responses must have a description
$.paths[*][get,post,put,patch,delete].responses[*]
warn
schema-description-required
Top-level component schemas should have descriptions
$.components.schemas[*]
info
schema-property-snake-case
Schema property names should use snake_case
$.components.schemas[*].properties
warn
security-global-defined
Global security must be defined
$
error
security-schemes-defined
Security schemes must be defined in components
$.components
info
security-bearer-auth
Better Stack API should use Bearer authentication
$.components.securitySchemes
error
http-get-no-body
GET operations should not have a request body
$.paths[*].get
warn
http-delete-no-body
DELETE operations should not have a request body
$.paths[*].delete
warn
http-post-has-body
POST operations should have a request body
$.paths[*].post
warn
http-patch-has-body
PATCH operations should have a request body
$.paths[*].patch
warn
no-empty-descriptions
Descriptions must not be empty strings
$..description
info
examples-encouraged
Schema properties should include example values
$.components.schemas[*].properties[*]
warn
servers-expected-domain
Server URLs should be on the betterstack.com domain.
$.servers[*].url
warn
path-params-casing
Path parameters should be snake_case (the dominant convention in this API).
$.paths[*].parameters[?(@.in=='path')].name
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
schema-names-casing
Component schema names should be PascalCase (the dominant convention in this API).
$.components.schemas
warn
schema-properties-casing
Schema properties should be snake_case (the dominant convention in this API).
$.components.schemas[*].properties
warn
error-schema-defined
A shared error schema (ErrorResponse) should be defined for error payloads.
$.components.schemas

Spectral Ruleset

Raw ↑
# better-stack — 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: 3/3 servers on betterstack.com
#   - path-params-casing: snake @ 100% (n=21)
#   - query-params-casing: snake @ 100% (n=15)
#   - operationid-casing: camel @ 100% (n=33)
#   - schema-names-casing: pascal @ 100% (n=39)
#   - schema-properties-casing: snake @ 100% (n=155)
#   - security: global (root) — NOT emitting operation-security-required
#   - error-schema-defined: ErrorResponse
#   - merge: kept 37 existing, added 6 measured, upgraded 0
#   - added: servers-expected-domain, path-params-casing, query-params-casing, schema-names-casing, schema-properties-casing, error-schema-defined
extends:
  - spectral:oas
rules:
  info-title-prefix:
    description: API title should start with "Better Stack"
    message: Info title should start with 'Better Stack' — got '{{value}}'
    severity: warn
    given: $.info.title
    then:
      function: pattern
      functionOptions:
        match: ^Better Stack
  info-description-required:
    description: API info must have a description
    severity: error
    given: $.info
    then:
      field: description
      function: truthy
  info-description-min-length:
    description: API description should be at least 30 characters
    message: 'Description is too short: {{value}}'
    severity: warn
    given: $.info.description
    then:
      function: length
      functionOptions:
        min: 30
  info-version-required:
    description: API info must specify a version
    severity: error
    given: $.info
    then:
      field: version
      function: truthy
  openapi-version:
    description: OpenAPI version should be 3.0.x
    message: OpenAPI version should be 3.0.x — got '{{value}}'
    severity: warn
    given: $.openapi
    then:
      function: pattern
      functionOptions:
        match: ^3\.0\.
  servers-defined:
    description: At least one server must be defined
    severity: error
    given: $
    then:
      field: servers
      function: truthy
  servers-https-only:
    description: All server URLs must use HTTPS
    message: Server URL must use HTTPS — got '{{value}}'
    severity: error
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: ^https://
  servers-description-required:
    description: Each server should have a description
    severity: warn
    given: $.servers[*]
    then:
      field: description
      function: truthy
  paths-kebab-case:
    description: Path segments should use kebab-case
    message: Path '{{path}}' should use kebab-case segments
    severity: warn
    given: $.paths
    then:
      function: pattern
      functionOptions:
        match: ^(/[a-z0-9-{}]+)+$
  paths-no-trailing-slash:
    description: Paths must not have trailing slashes
    message: Path '{{path}}' must not end with a slash
    severity: error
    given: $.paths
    then:
      function: pattern
      functionOptions:
        notMatch: /$
  paths-no-query-string:
    description: Query strings must not appear in paths
    message: Path '{{path}}' must not contain a query string
    severity: error
    given: $.paths
    then:
      function: pattern
      functionOptions:
        notMatch: \?
  operation-summary-required:
    description: All operations must have a summary
    severity: error
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: summary
      function: truthy
  operation-summary-title-case:
    description: Operation summaries should start with "Better Stack"
    message: Operation summary should start with 'Better Stack' — got '{{value}}'
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].summary
    then:
      function: pattern
      functionOptions:
        match: ^Better Stack
  operation-description-required:
    description: All operations must have a description
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: description
      function: truthy
  operation-id-required:
    description: All operations must have an operationId
    severity: error
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: operationId
      function: truthy
  operation-id-camel-case:
    description: operationId should use camelCase
    message: operationId '{{value}}' should use camelCase
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].operationId
    then:
      function: pattern
      functionOptions:
        match: ^[a-z][a-zA-Z0-9]+$
  operation-tags-required:
    description: All operations must have at least one tag
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: tags
      function: truthy
  tags-global-defined:
    description: Global tags array should be defined
    severity: info
    given: $
    then:
      field: tags
      function: truthy
  tags-description-required:
    description: Each global tag should have a description
    severity: info
    given: $.tags[*]
    then:
      field: description
      function: truthy
  parameter-description-required:
    description: All parameters must have a description
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    then:
      field: description
      function: truthy
  parameter-schema-required:
    description: All parameters must have a schema
    severity: error
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    then:
      field: schema
      function: truthy
  parameter-snake-case:
    description: Query parameter names should use snake_case
    message: Parameter '{{value}}' should use snake_case
    severity: info
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query')].name
    then:
      function: pattern
      functionOptions:
        match: ^[a-z][a-z0-9_]*$
  request-body-json-content:
    description: Request bodies should use application/json content type
    severity: warn
    given: $.paths[*][post,put,patch].requestBody.content
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          minProperties: 1
  response-success-required:
    description: Every operation must define a 2xx success response
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          anyOf:
          - required:
            - '200'
          - required:
            - '201'
          - required:
            - '204'
  response-401-defined:
    description: Operations should define a 401 Unauthorized response
    severity: info
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      function: schema
      functionOptions:
        schema:
          type: object
  response-description-required:
    description: All responses must have a description
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses[*]
    then:
      field: description
      function: truthy
  schema-description-required:
    description: Top-level component schemas should have descriptions
    severity: warn
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy
  schema-property-snake-case:
    description: Schema property names should use snake_case
    message: Property '{{path}}' should use snake_case
    severity: info
    given: $.components.schemas[*].properties
    then:
      function: schema
      functionOptions:
        schema:
          type: object
  security-global-defined:
    description: Global security must be defined
    severity: warn
    given: $
    then:
      field: security
      function: truthy
  security-schemes-defined:
    description: Security schemes must be defined in components
    severity: error
    given: $.components
    then:
      field: securitySchemes
      function: truthy
  security-bearer-auth:
    description: Better Stack API should use Bearer authentication
    severity: info
    given: $.components.securitySchemes
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          minProperties: 1
  http-get-no-body:
    description: GET operations should not have a request body
    severity: error
    given: $.paths[*].get
    then:
      field: requestBody
      function: falsy
  http-delete-no-body:
    description: DELETE operations should not have a request body
    severity: warn
    given: $.paths[*].delete
    then:
      field: requestBody
      function: falsy
  http-post-has-body:
    description: POST operations should have a request body
    severity: warn
    given: $.paths[*].post
    then:
      field: requestBody
      function: truthy
  http-patch-has-body:
    description: PATCH operations should have a request body
    severity: warn
    given: $.paths[*].patch
    then:
      field: requestBody
      function: truthy
  no-empty-descriptions:
    description: Descriptions must not be empty strings
    message: Description is empty at {{path}}
    severity: warn
    given: $..description
    then:
      function: pattern
      functionOptions:
        match: .+
  examples-encouraged:
    description: Schema properties should include example values
    severity: info
    given: $.components.schemas[*].properties[*]
    then:
      function: schema
      functionOptions:
        schema:
          type: object
  servers-expected-domain:
    description: Server URLs should be on the betterstack.com domain.
    severity: warn
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: betterstack\.com
  path-params-casing:
    description: Path parameters should be snake_case (the dominant convention in this API).
    severity: warn
    given: $.paths[*].parameters[?(@.in=='path')].name
    then:
      function: casing
      functionOptions:
        type: snake
  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
  schema-names-casing:
    description: Component schema names should be PascalCase (the dominant convention in this API).
    severity: warn
    given: $.components.schemas
    then:
      field: '@key'
      function: casing
      functionOptions:
        type: pascal
  schema-properties-casing:
    description: Schema properties should be snake_case (the dominant convention in this API).
    severity: warn
    given: $.components.schemas[*].properties
    then:
      field: '@key'
      function: casing
      functionOptions:
        type: snake
  error-schema-defined:
    description: A shared error schema (ErrorResponse) should be defined for error payloads.
    severity: warn
    given: $.components.schemas
    then:
      field: ErrorResponse
      function: truthy