Backblaze · API Governance Rules

Backblaze API Rules

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

31 Rules error 12 warn 12 info 7
View Rules File View on GitHub

Rule Categories

components get info no openapi operation parameter paths post request response schema security servers tags

Rules

error
info-title-required
Info must have a title
$.info
warn
info-description-required
Info must have a description
$.info
error
info-version-required
Info must have a version
$.info
info
info-contact-required
Info should have contact information
$.info
error
openapi-version-3
Must use OpenAPI 3.0.x
$
error
servers-defined
Servers must be defined
$
error
servers-https-only
All server URLs must use HTTPS
$.servers[*].url
warn
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths
warn
paths-b2-api-prefix
B2 Native API paths should use /b2api/v{version}/ prefix
$.paths
error
operation-summary-required
Every operation must have a summary
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-description-required
Every operation must have a description
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-id-required
Every operation must have an operationId
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-id-camel-case
OperationIds should use camelCase
$.paths[*][get,post,put,patch,delete,head,options].operationId
warn
operation-tags-required
Every operation must have at least one tag
$.paths[*][get,post,put,patch,delete,head,options]
info
operation-summary-backblaze-prefix
Operation summaries should start with "Backblaze B2"
$.paths[*][get,post,put,patch,delete,head,options].summary
info
tags-global-defined
Global tags array should be defined
$
warn
parameter-description-required
All parameters must have descriptions
$.paths[*][get,post,put,patch,delete,head,options].parameters[*]
error
parameter-schema-required
All parameters must have a schema
$.paths[*][get,post,put,patch,delete,head,options].parameters[*]
info
request-body-description
Request bodies should have descriptions
$.paths[*][post,put,patch].requestBody
error
response-success-required
Every operation must have at least one 2xx response
$.paths[*][get,post,put,patch,delete]
error
response-description-required
Every response must have a description
$.paths[*][get,post,put,patch,delete].responses[*]
warn
response-401-defined
Operations with auth should define 401 response
$.paths[*][post,get]
warn
schema-type-defined
All schemas should have a type
$.components.schemas[*]
info
schema-title-defined
All component schemas should have a title
$.components.schemas[*]
info
schema-description-defined
All component schemas should have a description
$.components.schemas[*]
error
security-schemes-defined
Security schemes must be defined in components
$.components
warn
security-global-defined
Global security should be defined
$
error
get-no-request-body
GET operations must not have a request body
$.paths[*].get
warn
post-b2-operations-have-request-body
POST operations should have a request body
$.paths[*].post
warn
no-empty-descriptions
Descriptions must not be empty strings
$..description
info
components-schemas-present
Spec should define reusable schemas in components
$.components

Spectral Ruleset

Raw ↑
rules:

  # INFO / METADATA
  info-title-required:
    description: Info must have a title
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  info-description-required:
    description: Info must have a description
    severity: warn
    given: $.info
    then:
      field: description
      function: truthy

  info-version-required:
    description: Info must have a version
    severity: error
    given: $.info
    then:
      field: version
      function: truthy

  info-contact-required:
    description: Info should have contact information
    severity: info
    given: $.info
    then:
      field: contact
      function: truthy

  # OPENAPI VERSION
  openapi-version-3:
    description: Must use OpenAPI 3.0.x
    severity: error
    given: $
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: "^3\\.0\\."

  # SERVERS
  servers-defined:
    description: Servers must be defined
    severity: error
    given: $
    then:
      field: servers
      function: truthy

  servers-https-only:
    description: All server URLs must use HTTPS
    severity: error
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  # PATHS — NAMING CONVENTIONS
  paths-no-trailing-slash:
    description: Paths must not have trailing slashes
    severity: warn
    given: $.paths
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  paths-b2-api-prefix:
    description: B2 Native API paths should use /b2api/v{version}/ prefix
    severity: warn
    given: $.paths
    then:
      function: pattern
      functionOptions:
        match: "^/b2api/"

  # OPERATIONS
  operation-summary-required:
    description: Every operation must have a summary
    severity: error
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: summary
      function: truthy

  operation-description-required:
    description: Every operation must have a description
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: description
      function: truthy

  operation-id-required:
    description: Every operation 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: OperationIds should use camelCase
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options].operationId
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  operation-tags-required:
    description: Every operation must have at least one tag
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: tags
      function: truthy

  operation-summary-backblaze-prefix:
    description: Operation summaries should start with "Backblaze B2"
    severity: info
    given: $.paths[*][get,post,put,patch,delete,head,options].summary
    then:
      function: pattern
      functionOptions:
        match: "^Backblaze"

  # TAGS
  tags-global-defined:
    description: Global tags array should be defined
    severity: info
    given: $
    then:
      field: tags
      function: truthy

  # PARAMETERS
  parameter-description-required:
    description: All parameters must have descriptions
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options].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,head,options].parameters[*]
    then:
      field: schema
      function: truthy

  # REQUEST BODIES
  request-body-description:
    description: Request bodies should have descriptions
    severity: info
    given: $.paths[*][post,put,patch].requestBody
    then:
      field: description
      function: truthy

  # RESPONSES
  response-success-required:
    description: Every operation must have at least one 2xx response
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: responses
      function: truthy

  response-description-required:
    description: Every response must have a description
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses[*]
    then:
      field: description
      function: truthy

  response-401-defined:
    description: Operations with auth should define 401 response
    severity: warn
    given: $.paths[*][post,get]
    then:
      field: responses.401
      function: truthy

  # SCHEMAS — PROPERTY NAMING
  schema-type-defined:
    description: All schemas should have a type
    severity: warn
    given: $.components.schemas[*]
    then:
      field: type
      function: truthy

  schema-title-defined:
    description: All component schemas should have a title
    severity: info
    given: $.components.schemas[*]
    then:
      field: title
      function: truthy

  schema-description-defined:
    description: All component schemas should have a description
    severity: info
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy

  # SECURITY
  security-schemes-defined:
    description: Security schemes must be defined in components
    severity: error
    given: $.components
    then:
      field: securitySchemes
      function: truthy

  security-global-defined:
    description: Global security should be defined
    severity: warn
    given: $
    then:
      field: security
      function: truthy

  # HTTP METHOD CONVENTIONS
  get-no-request-body:
    description: GET operations must not have a request body
    severity: error
    given: $.paths[*].get
    then:
      field: requestBody
      function: falsy

  post-b2-operations-have-request-body:
    description: POST operations should have a request body
    severity: warn
    given: $.paths[*].post
    then:
      field: requestBody
      function: truthy

  # GENERAL QUALITY
  no-empty-descriptions:
    description: Descriptions must not be empty strings
    severity: warn
    given: $..description
    then:
      function: truthy

  components-schemas-present:
    description: Spec should define reusable schemas in components
    severity: info
    given: $.components
    then:
      field: schemas
      function: truthy