CloudEvents · API Governance Rules

CloudEvents API Rules

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

9 Rules error 3 warn 6
View Rules File View on GitHub

Rule Categories

cloudevents

Rules

error
cloudevents-info-contact
API contact information must be present.
$.info
warn
cloudevents-info-license
API license must be declared (CloudEvents publishes under Apache-2.0).
$.info
warn
cloudevents-info-license-apache
CloudEvents-aligned APIs should declare an Apache-2.0 license.
$.info.license.name
error
cloudevents-server-https
All server URLs must use HTTPS.
$.servers[*].url
error
cloudevents-operation-id
Every operation must declare a unique operationId.
$.paths[*][get,post,put,patch,delete]
warn
cloudevents-operation-tags
Every operation must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
cloudevents-operation-summary
Every operation must include a short summary.
$.paths[*][get,post,put,patch,delete]
warn
cloudevents-error-responses
Mutating operations should declare 4xx error responses.
$.paths[*][post,put,patch,delete].responses
warn
cloudevents-subscription-required-attributes
Subscription schemas must include the CloudEvents-required `id`, `source`, and `sink` attributes.
$.components.schemas.Subscription.properties

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

# Spectral linting rules for the CloudEvents Subscriptions API and any
# OpenAPI describing CloudEvents-compliant endpoints.
rules:
  cloudevents-info-contact:
    description: API contact information must be present.
    severity: error
    given: "$.info"
    then:
      field: contact
      function: truthy

  cloudevents-info-license:
    description: API license must be declared (CloudEvents publishes under Apache-2.0).
    severity: warn
    given: "$.info"
    then:
      field: license
      function: truthy

  cloudevents-info-license-apache:
    description: CloudEvents-aligned APIs should declare an Apache-2.0 license.
    severity: warn
    given: "$.info.license.name"
    then:
      function: pattern
      functionOptions:
        match: "(?i)apache"

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

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

  cloudevents-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

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

  cloudevents-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"]

  cloudevents-subscription-required-attributes:
    description: Subscription schemas must include the CloudEvents-required `id`, `source`, and `sink` attributes.
    severity: warn
    given: "$.components.schemas.Subscription.properties"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          required: ["id", "source", "sink"]