Bitbucket · API Governance Rules

Bitbucket API Rules

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

19 Rules error 8 warn 9 info 2
View Rules File View on GitHub

Rule Categories

delete get info operation pagination parameter paths response schema security tag

Rules

error
info-title-required
Info object must have a title
$.info
error
info-description-required
Info object must have a description
$.info
error
info-version-required
Info object must have a version
$.info
warn
paths-kebab-case
Path segments should use kebab-case
$.paths
error
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths
error
operation-summary-required
Operations must have a summary
$.paths[*][get,post,put,patch,delete]
warn
operation-description-required
Operations must have a description
$.paths[*][get,post,put,patch,delete]
error
operation-operationid-required
Operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
operation-tags-required
Operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
info
operation-summary-prefix
Operation summaries should start with Bitbucket
$.paths[*][get,post,put,patch,delete].summary
warn
parameter-description-required
Parameters must have descriptions
$.paths[*][get,post,put,patch,delete].parameters[*]
error
response-success-required
Operations must define a success response
$.paths[*][get,post,put,patch,delete].responses
warn
schema-type-required
Schemas should have a type defined
$.definitions[*]
warn
schema-property-snake-case
Schema properties should use snake_case
$.definitions[*].properties
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
delete-no-request-body
DELETE operations should not have a request body
$.paths[*].delete
info
pagination-use-page
Paginated endpoints should use page-based pagination
$.paths[*].get.parameters[?(@.name=='page')]
warn
tag-title-case
Tag names should use Title Case
$.tags[*].name

Spectral Ruleset

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

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

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

  # PATHS
  paths-kebab-case:
    description: Path segments should use kebab-case
    given: $.paths
    severity: warn
    then:
      field: "@key"
      function: pattern
      functionOptions:
        match: "^(/[a-z0-9_-]+(/{[a-zA-Z_]+})?)*$"

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

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

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

  operation-operationid-required:
    description: Operations must have an operationId
    given: $.paths[*][get,post,put,patch,delete]
    severity: error
    then:
      field: operationId
      function: truthy

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

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

  # PARAMETERS
  parameter-description-required:
    description: Parameters must have descriptions
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    severity: warn
    then:
      field: description
      function: truthy

  # RESPONSES
  response-success-required:
    description: Operations must define a success response
    given: $.paths[*][get,post,put,patch,delete].responses
    severity: error
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["200"]
            - required: ["201"]
            - required: ["204"]

  # SCHEMAS
  schema-type-required:
    description: Schemas should have a type defined
    given: $.definitions[*]
    severity: warn
    then:
      field: type
      function: truthy

  # PROPERTY NAMING
  schema-property-snake-case:
    description: Schema properties should use snake_case
    given: $.definitions[*].properties
    severity: warn
    then:
      field: "@key"
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

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

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

  delete-no-request-body:
    description: DELETE operations should not have a request body
    given: $.paths[*].delete
    severity: warn
    then:
      field: requestBody
      function: falsy

  # PAGINATION
  pagination-use-page:
    description: Paginated endpoints should use page-based pagination
    given: $.paths[*].get.parameters[?(@.name=='page')]
    severity: info
    then:
      field: name
      function: truthy

  # TAGS
  tag-title-case:
    description: Tag names should use Title Case
    given: $.tags[*].name
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"