Backstage · API Governance Rules

Backstage API Rules

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

21 Rules error 8 warn 10 info 3
View Rules File View on GitHub

Rule Categories

get info no openapi operation parameter paths response schema security servers

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
error
openapi-version-3
Must use OpenAPI 3.0.x or 3.1.x
$
warn
servers-defined
Servers must be defined
$
warn
paths-kebab-case
Path segments should use kebab-case
$.paths
warn
paths-no-trailing-slash
Paths must not have trailing slashes
$.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-backstage-prefix
Operation summaries should start with "Backstage"
$.paths[*][get,post,put,patch,delete,head,options].summary
warn
parameter-description-required
All parameters must have descriptions
$.paths[*][get,post,put,patch,delete,head,options].parameters[*]
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[*]
info
response-401-defined
Protected operations should define a 401 response
$.paths[*][post,put,patch,delete]
warn
schema-type-defined
All schemas should have a type
$.components.schemas[*]
info
security-schemes-defined
Security schemes must be defined if auth is used
$.components
error
get-no-request-body
GET operations must not have a request body
$.paths[*].get
warn
no-empty-descriptions
Descriptions must not be empty strings
$..description

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

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

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

  # PATHS — NAMING CONVENTIONS
  paths-kebab-case:
    description: Path segments should use kebab-case
    severity: warn
    given: $.paths
    then:
      function: pattern
      functionOptions:
        match: "^(/[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*|/\\{[a-zA-Z0-9_]+\\})*)*$"

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

  # 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-backstage-prefix:
    description: Operation summaries should start with "Backstage"
    severity: info
    given: $.paths[*][get,post,put,patch,delete,head,options].summary
    then:
      function: pattern
      functionOptions:
        match: "^Backstage"

  # 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

  # 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: Protected operations should define a 401 response
    severity: info
    given: $.paths[*][post,put,patch,delete]
    then:
      field: responses.401
      function: truthy

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

  # SECURITY
  security-schemes-defined:
    description: Security schemes must be defined if auth is used
    severity: info
    given: $.components
    then:
      field: securitySchemes
      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

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