Staples · API Governance Rules

Staples API Rules

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

21 Rules error 9 warn 10 info 2
View Rules File View on GitHub

Rule Categories

staples

Rules

warn
staples-operation-ids-camel-case
Operation IDs must use camelCase naming convention
$.paths[*][*].operationId
warn
staples-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][*].summary
error
staples-api-versioned-paths
All API paths must be versioned with /v1/ prefix
$.paths
error
staples-bearer-auth-required
All operations must use Bearer token authentication
$.paths[*][*]
error
staples-get-operations-200
GET operations must define a 200 response
$.paths[*].get
error
staples-post-create-201
POST create operations must return 201 Created
$.paths[*].post
error
staples-unauthorized-response
All operations must define a 401 Unauthorized response
$.paths[*][*]
warn
staples-not-found-response
Operations with path parameters should define 404
$.paths[*][*]
warn
staples-rate-limit-response
All operations must define a 429 Too Many Requests response
$.paths[*][*]
warn
staples-operation-tags-required
All operations must have at least one tag
$.paths[*][*].tags
warn
staples-tags-title-case
All tags must use Title Case
$.paths[*][*].tags[*]
warn
staples-path-kebab-case
Path segments must use kebab-case
$.paths
warn
staples-no-trailing-slash
Paths must not have a trailing slash
$.paths
error
staples-path-parameters-required
Path parameters must be marked as required
$.paths[*][*].parameters[?(@.in=='path')]
warn
staples-query-parameters-described
Query parameters must have descriptions
$.paths[*][*].parameters[?(@.in=='query')]
error
staples-post-request-body
POST operations must define a request body
$.paths[*].post
info
staples-schemas-have-descriptions
Schema components should have descriptions where possible
$.components.schemas[*]
warn
staples-info-contact
API must have contact information
$.info
info
staples-info-terms
API must reference terms of service
$.info
error
staples-info-description
API must have a description
$.info
error
staples-servers-defined
API must define at least one server
$

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Operation naming and structure
  staples-operation-ids-camel-case:
    description: Operation IDs must use camelCase naming convention
    message: "Operation ID '{{value}}' must use camelCase (e.g., searchProducts, createOrder)"
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  staples-operation-summary-title-case:
    description: Operation summaries must use Title Case
    message: "Summary '{{value}}' should use Title Case"
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9 &]*$"

  staples-api-versioned-paths:
    description: All API paths must be versioned with /v1/ prefix
    message: "Path '{{property}}' must start with /v1/"
    severity: error
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^/v[0-9]+"

  # Authentication requirements
  staples-bearer-auth-required:
    description: All operations must use Bearer token authentication
    message: "Operation must reference bearerAuth security scheme"
    severity: error
    given: "$.paths[*][*]"
    then:
      function: schema
      functionOptions:
        schema:
          properties:
            security:
              type: array
          required:
            - security

  # Response codes
  staples-get-operations-200:
    description: GET operations must define a 200 response
    message: "GET operation must have a 200 response defined"
    severity: error
    given: "$.paths[*].get"
    then:
      field: "responses.200"
      function: truthy

  staples-post-create-201:
    description: POST create operations must return 201 Created
    message: "POST operation creating resources must return 201 Created"
    severity: error
    given: "$.paths[*].post"
    then:
      field: "responses.201"
      function: truthy

  staples-unauthorized-response:
    description: All operations must define a 401 Unauthorized response
    message: "Operation must define a 401 Unauthorized response"
    severity: error
    given: "$.paths[*][*]"
    then:
      field: "responses.401"
      function: truthy

  staples-not-found-response:
    description: Operations with path parameters should define 404
    message: "Operation with path parameters should define a 404 Not Found response"
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: "responses.404"
      function: truthy

  staples-rate-limit-response:
    description: All operations must define a 429 Too Many Requests response
    message: "Operation must define a 429 Too Many Requests response"
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: "responses.429"
      function: truthy

  # Tags
  staples-operation-tags-required:
    description: All operations must have at least one tag
    message: "Operation must include at least one tag"
    severity: warn
    given: "$.paths[*][*].tags"
    then:
      function: length
      functionOptions:
        min: 1

  staples-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][a-zA-Z0-9 ]*$"

  # Path conventions
  staples-path-kebab-case:
    description: Path segments must use kebab-case
    message: "Path must use kebab-case (lowercase, hyphens, path params)"
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^[/a-z0-9{}-]*$"

  staples-no-trailing-slash:
    description: Paths must not have a trailing slash
    message: "Path '{{property}}' must not end with a trailing slash"
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  # Parameter requirements
  staples-path-parameters-required:
    description: Path parameters must be marked as required
    message: "Path parameter must have required: true"
    severity: error
    given: "$.paths[*][*].parameters[?(@.in=='path')]"
    then:
      field: required
      function: truthy

  staples-query-parameters-described:
    description: Query parameters must have descriptions
    message: "Query parameter must have a description"
    severity: warn
    given: "$.paths[*][*].parameters[?(@.in=='query')]"
    then:
      field: description
      function: truthy

  # Request body for POST/PUT
  staples-post-request-body:
    description: POST operations must define a request body
    message: "POST operation must include a requestBody definition"
    severity: error
    given: "$.paths[*].post"
    then:
      field: requestBody
      function: truthy

  # Schema requirements
  staples-schemas-have-descriptions:
    description: Schema components should have descriptions where possible
    message: "Schema should include descriptive information"
    severity: info
    given: "$.components.schemas[*]"
    then:
      field: type
      function: truthy

  # Info
  staples-info-contact:
    description: API must have contact information
    message: "API info must include contact details"
    severity: warn
    given: "$.info"
    then:
      field: contact
      function: truthy

  staples-info-terms:
    description: API must reference terms of service
    message: "API info should include termsOfService"
    severity: info
    given: "$.info"
    then:
      field: termsOfService
      function: truthy

  staples-info-description:
    description: API must have a description
    message: "API info must include a description"
    severity: error
    given: "$.info"
    then:
      field: description
      function: truthy

  staples-servers-defined:
    description: API must define at least one server
    message: "API must define servers with base URL"
    severity: error
    given: "$"
    then:
      field: servers
      function: truthy