Cockroach Labs · API Governance Rules

Cockroach Labs API Rules

Spectral linting rules defining API design standards and conventions for Cockroach Labs.

10 Rules error 3 warn 4 info 3
View Rules File View on GitHub

Rule Categories

cockroach

Rules

error
cockroach-labs-info-contact
API contact information must be present.
$.info
warn
cockroach-labs-terms-of-service
termsOfService must reference cockroachlabs.com.
$.info.termsOfService
warn
cockroach-labs-server-https
Public server URLs must use HTTPS (cluster API loopback exempt).
$.servers[?(@.url && @.url.indexOf('localhost') === -1)].url
info
cockroach-labs-cloud-base-host
Cloud API server URL must point to cockroachlabs.cloud.
$.servers[?(@.url && @.url.indexOf('cockroachlabs.cloud') > -1)].url
error
cockroach-labs-bearer-security
Cloud API operations must define a bearer-token security scheme.
$.components.securitySchemes[*]
error
cockroach-labs-operation-id
Every operation must declare a unique operationId.
$.paths[*][get,post,put,patch,delete]
warn
cockroach-labs-operation-tags
Operations must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
cockroach-labs-error-responses
Mutating operations should declare 4xx/5xx error responses.
$.paths[*][post,put,patch,delete].responses
info
cockroach-labs-uuid-cluster-id
Path parameters named cluster_id should be UUIDs.
$.paths[*].*.parameters[?(@.in == 'path' && @.name == 'cluster_id')].schema
info
cockroach-labs-cc-version-header
Cloud API requests should support the Cc-Version versioning header.
$.paths[*][get,post,put,patch,delete].parameters[?(@.in == 'header')]

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

# Spectral linting rules for Cockroach Labs APIs.
# Tuned to cockroachlabs.cloud (Cloud API) and per-node /api/v2 (Cluster API)
# conventions: HTTPS for cloud, bearer tokens, Cc-Version header, UUID
# resource identifiers, and standardized error envelopes.
rules:
  cockroach-labs-info-contact:
    description: API contact information must be present.
    severity: error
    given: "$.info"
    then:
      field: contact
      function: truthy

  cockroach-labs-terms-of-service:
    description: termsOfService must reference cockroachlabs.com.
    severity: warn
    given: "$.info.termsOfService"
    then:
      function: pattern
      functionOptions:
        match: "cockroachlabs.com"

  cockroach-labs-server-https:
    description: Public server URLs must use HTTPS (cluster API loopback exempt).
    severity: warn
    given: "$.servers[?(@.url && @.url.indexOf('localhost') === -1)].url"
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  cockroach-labs-cloud-base-host:
    description: Cloud API server URL must point to cockroachlabs.cloud.
    severity: info
    given: "$.servers[?(@.url && @.url.indexOf('cockroachlabs.cloud') > -1)].url"
    then:
      function: pattern
      functionOptions:
        match: "cockroachlabs.cloud"

  cockroach-labs-bearer-security:
    description: Cloud API operations must define a bearer-token security scheme.
    severity: error
    given: "$.components.securitySchemes[*]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            type:
              enum: ["http", "apiKey", "oauth2"]

  cockroach-labs-operation-id:
    description: Every operation must declare a unique operationId.
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  cockroach-labs-operation-tags:
    description: Operations must declare at least one tag.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: schema
      functionOptions:
        schema:
          type: array
          minItems: 1

  cockroach-labs-error-responses:
    description: Mutating operations should declare 4xx/5xx error responses.
    severity: warn
    given: "$.paths[*][post,put,patch,delete].responses"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          anyOf:
            - required: ["400"]
            - required: ["401"]
            - required: ["403"]
            - required: ["404"]
            - required: ["429"]

  cockroach-labs-uuid-cluster-id:
    description: Path parameters named cluster_id should be UUIDs.
    severity: info
    given: "$.paths[*].*.parameters[?(@.in == 'path' && @.name == 'cluster_id')].schema"
    then:
      field: format
      function: enumeration
      functionOptions:
        values:
          - uuid

  cockroach-labs-cc-version-header:
    description: Cloud API requests should support the Cc-Version versioning header.
    severity: info
    given: "$.paths[*][get,post,put,patch,delete].parameters[?(@.in == 'header')]"
    then:
      field: name
      function: enumeration
      functionOptions:
        values:
          - Cc-Version
          - X-Cockroach-API-Session
          - Authorization