Rook · API Governance Rules

Rook API Rules

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

9 Rules error 2 warn 5 info 2
View Rules File View on GitHub

Rule Categories

rook

Rules

warn
rook-operation-summary-title-case
All operation summaries must use Title Case
$.paths[*][*].summary
warn
rook-operation-id-camel-case
operationId must use camelCase
$.paths[*][*].operationId
error
rook-s3-path-bucket-required
S3 paths with /{key} must also include /{bucket} parameter
$.paths[*][get,put,delete,head].parameters[?(@.in == 'path')]
info
rook-s3-response-xml-content-type
S3-compatible responses should use application/xml content type
$.paths[*][*].responses[*].content
warn
rook-operation-description-required
All operations must have a description
$.paths[*][get,put,post,delete,head]
warn
rook-tags-title-case
All tags must use Title Case
$.paths[*][*].tags[*]
info
rook-error-response-schema
Error responses should reference an ErrorResponse schema
$.paths[*][*].responses[4xx,5xx]
error
rook-server-defined
At least one server must be defined
$
warn
rook-info-contact
Info object must include contact information
$.info

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Rook S3-compatible API conventions
  rook-operation-summary-title-case:
    description: All operation summaries must use Title Case
    message: "Operation summary '{{value}}' must use Title Case"
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][^a-z]*([A-Z][^A-Z]*)*$|^([A-Z][a-z]*(\\s[A-Z]?[a-z]*)*[A-Z]?[a-z]*)$"

  rook-operation-id-camel-case:
    description: operationId must use camelCase
    message: "operationId '{{value}}' should use camelCase"
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  rook-s3-path-bucket-required:
    description: S3 paths with /{key} must also include /{bucket} parameter
    message: "S3 path operations on objects must define the 'bucket' path parameter"
    severity: error
    given: "$.paths[*][get,put,delete,head].parameters[?(@.in == 'path')]"
    then:
      field: name
      function: enumeration
      functionOptions:
        values:
          - bucket
          - key

  rook-s3-response-xml-content-type:
    description: S3-compatible responses should use application/xml content type
    message: "S3 object storage responses should declare application/xml or application/octet-stream content types"
    severity: info
    given: "$.paths[*][*].responses[*].content"
    then:
      function: truthy

  rook-operation-description-required:
    description: All operations must have a description
    message: "Operation is missing a description"
    severity: warn
    given: "$.paths[*][get,put,post,delete,head]"
    then:
      field: description
      function: truthy

  rook-tags-title-case:
    description: All tags must use Title Case
    message: "Tag '{{value}}' must use Title Case"
    severity: warn
    given: "$.paths[*][*].tags[*]"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  rook-error-response-schema:
    description: Error responses should reference an ErrorResponse schema
    message: "4xx and 5xx responses should include an error response schema"
    severity: info
    given: "$.paths[*][*].responses[4xx,5xx]"
    then:
      field: content
      function: truthy

  rook-server-defined:
    description: At least one server must be defined
    message: "OpenAPI spec must define at least one server"
    severity: error
    given: "$"
    then:
      field: servers
      function: truthy

  rook-info-contact:
    description: Info object must include contact information
    message: "OpenAPI info must include a contact block"
    severity: warn
    given: "$.info"
    then:
      field: contact
      function: truthy