Apple CloudKit · API Governance Rules

Apple CloudKit API Rules

Spectral linting rules defining API design standards and conventions for Apple CloudKit.

12 Rules error 4 warn 6 info 2
View Rules File View on GitHub

Rule Categories

cloudkit

Rules

error
cloudkit-info-contact
API contact information must be present.
$.info
warn
cloudkit-info-license
API license must be declared.
$.info
error
cloudkit-server-https
All server URLs must use HTTPS.
$.servers[*].url
warn
cloudkit-server-base
CloudKit server URLs must point at api.apple-cloudkit.com.
$.servers[*].url
warn
cloudkit-database-versioned
CloudKit paths must include /database/{version}.
$.servers[*].url
info
cloudkit-environment
Paths should specify development or production environment.
$.paths[*]
error
cloudkit-auth
A security scheme must be declared (apiKey or signature-based).
$.components.securitySchemes
info
cloudkit-token-param
Operations using API token auth should declare ckAPIToken.
$.paths[*][get,post].parameters[?(@.in == 'query')].name
error
cloudkit-operation-id
Every operation must declare a unique operationId.
$.paths[*][get,post,put,patch,delete]
warn
cloudkit-operation-summary
Every operation must include a short summary.
$.paths[*][get,post,put,patch,delete]
warn
cloudkit-operation-tags
Every operation must declare at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
cloudkit-error-responses
Mutating operations should declare 4xx error responses.
$.paths[*][post,put,patch,delete].responses

Spectral Ruleset

cloudkit-rules.yml Raw ↑
extends:
  - spectral:oas

# Spectral linting rules for the Apple CloudKit Web Services API.
# Validates CloudKit's path shape (/database/1/{container}/{env}/{db})
# and the auth/query parameter conventions used by the web service.
rules:
  cloudkit-info-contact:
    description: API contact information must be present.
    severity: error
    given: "$.info"
    then:
      field: contact
      function: truthy

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

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

  cloudkit-server-base:
    description: CloudKit server URLs must point at api.apple-cloudkit.com.
    severity: warn
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: "api\\.apple-cloudkit\\.com"

  cloudkit-database-versioned:
    description: CloudKit paths must include /database/{version}.
    severity: warn
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: "/database/\\d+(/|$)"

  cloudkit-environment:
    description: Paths should specify development or production environment.
    severity: info
    given: "$.paths[*]"
    then:
      function: pattern
      functionOptions:
        match: "(development|production)"

  cloudkit-auth:
    description: A security scheme must be declared (apiKey or signature-based).
    severity: error
    given: "$.components.securitySchemes"
    then:
      function: truthy

  cloudkit-token-param:
    description: Operations using API token auth should declare ckAPIToken.
    severity: info
    given: "$.paths[*][get,post].parameters[?(@.in == 'query')].name"
    then:
      function: enumeration
      functionOptions:
        values:
          - ckAPIToken
          - ckWebAuthToken
          - ckSession

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

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

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

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