CloudZero · API Governance Rules

CloudZero API Rules

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

12 Rules error 4 warn 7 info 1
View Rules File View on GitHub

Rule Categories

cloudzero

Rules

error
cloudzero-info-contact
API contact information must be present.
$.info
warn
cloudzero-info-license
API license must be declared.
$.info
error
cloudzero-server-https
All server URLs must use HTTPS.
$.servers[*].url
warn
cloudzero-server-host
Server URL must reference api.cloudzero.com.
$.servers[*].url
error
cloudzero-api-key-auth
An apiKey security scheme must be defined.
$.components.securitySchemes
warn
cloudzero-operation-tags
Every operation must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
cloudzero-operation-summary
Every operation must include a short summary.
$.paths[*][get,post,put,patch,delete]
error
cloudzero-operation-id
Every operation must declare a unique operationId.
$.paths[*][get,post,put,patch,delete]
warn
cloudzero-error-responses
Mutating operations should declare 4xx error responses.
$.paths[*][post,put,patch,delete].responses
info
cloudzero-pagination-page
List endpoints should accept page and page_size query parameters.
$.paths[?(@property.match(/insights$|budgets$|costs$|dimensions$/))].get.parameters[*].name
warn
cloudzero-iso-date
Date parameters and properties should use ISO 8601 (date or date-time).
$..[?(@property === 'start_date' || @property === 'end_date')].schema
warn
cloudzero-currency-iso
Currency fields should use ISO 4217 codes.
$..[?(@property === 'currency')].schema

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

# Spectral linting rules tuned for the CloudZero V2 REST API.
# Validates conventions described at
# https://docs.cloudzero.com/reference/introduction
# - HTTPS only, API key authentication, JSON request/response,
#   page/page_size pagination, and resource-oriented v1/v2 paths.
rules:
  cloudzero-info-contact:
    description: API contact information must be present.
    severity: error
    given: "$.info"
    then:
      field: contact
      function: truthy

  cloudzero-info-license:
    description: API license must be declared.
    severity: warn
    given: "$.info"
    then:
      field: license
      function: truthy

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

  cloudzero-server-host:
    description: Server URL must reference api.cloudzero.com.
    severity: warn
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: "api\\.cloudzero\\.com"

  cloudzero-api-key-auth:
    description: An apiKey security scheme must be defined.
    severity: error
    given: "$.components.securitySchemes"
    then:
      function: truthy

  cloudzero-operation-tags:
    description: Every operation 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

  cloudzero-operation-summary:
    description: Every operation must include a short summary.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: summary
      function: truthy

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

  cloudzero-error-responses:
    description: Mutating operations should declare 4xx 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: ["422"]

  cloudzero-pagination-page:
    description: List endpoints should accept page and page_size query parameters.
    severity: info
    given: "$.paths[?(@property.match(/insights$|budgets$|costs$|dimensions$/))].get.parameters[*].name"
    then:
      function: enumeration
      functionOptions:
        values:
          - page
          - page_size
          - filter
          - dimensions
          - metrics
          - start_date
          - end_date

  cloudzero-iso-date:
    description: Date parameters and properties should use ISO 8601 (date or date-time).
    severity: warn
    given: "$..[?(@property === 'start_date' || @property === 'end_date')].schema"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            format:
              type: string
              enum:
                - date
                - date-time

  cloudzero-currency-iso:
    description: Currency fields should use ISO 4217 codes.
    severity: warn
    given: "$..[?(@property === 'currency')].schema"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            pattern:
              type: string
              enum:
                - "^[A-Z]{3}$"