Contour · API Governance Rules

Contour API Rules

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

5 Rules error 4 warn 1
View Rules File View on GitHub

Rule Categories

contour

Rules

error
contour-gateway-info-title
Gateway OpenAPI info.title must reference Contour Gateway
$.info.title
error
contour-gateway-server-defined
At least one server URL must be defined for the Kubernetes API
$.servers
warn
contour-gateway-tag-required
Tags must declare GatewayClass, Gateway, HTTPRoute, or TLSRoute scope
$.tags[*].name
error
contour-gateway-operation-id-camelcase
Every operation must define an operationId using camelCase
$.paths.*[get,put,post,delete,patch].operationId
error
contour-gateway-api-group-prefix
Gateway API paths must live under /apis/gateway.networking.k8s.io
$.paths

Spectral Ruleset

Raw ↑
extends:
  - "spectral:oas"
documentationUrl: https://projectcontour.io/docs/main/config/gateway-api/
rules:
  contour-gateway-info-title:
    description: Gateway OpenAPI info.title must reference Contour Gateway
    severity: error
    given: "$.info.title"
    then:
      function: pattern
      functionOptions:
        match: "(?i)Contour\\s+Gateway"
  contour-gateway-server-defined:
    description: At least one server URL must be defined for the Kubernetes API
    severity: error
    given: "$.servers"
    then:
      function: length
      functionOptions:
        min: 1
  contour-gateway-tag-required:
    description: Tags must declare GatewayClass, Gateway, HTTPRoute, or TLSRoute scope
    severity: warn
    given: "$.tags[*].name"
    then:
      function: enumeration
      functionOptions:
        values:
          - GatewayClass
          - Gateway
          - HTTPRoute
          - TLSRoute
          - GRPCRoute
          - TCPRoute
          - UDPRoute
  contour-gateway-operation-id-camelcase:
    description: Every operation must define an operationId using camelCase
    severity: error
    given: "$.paths.*[get,put,post,delete,patch].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"
  contour-gateway-api-group-prefix:
    description: Gateway API paths must live under /apis/gateway.networking.k8s.io
    severity: error
    given: "$.paths"
    then:
      field: "@key"
      function: pattern
      functionOptions:
        match: "^/apis/gateway\\.networking\\.k8s\\.io/"