Stack Exchange · API Governance Rules

Stack Exchange API Rules

Spectral linting rules defining API design standards and conventions for Stack Exchange.

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

Rule Categories

stack

Rules

warn
stack-exchange-operation-summaries-title-case
All Stack Exchange API operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
warn
stack-exchange-site-parameter-required
Stack Exchange API endpoints must require the site query parameter
$.paths[*][get,post,put,patch,delete].parameters[*]
warn
stack-exchange-operationid-camel-case
Stack Exchange API operationIds must use camelCase
$.paths[*][get,post,put,patch,delete].operationId
error
stack-exchange-operations-must-have-operationid
All Stack Exchange API operations must have an operationId
$.paths[*][get,post,put,patch,delete]
info
stack-exchange-semicolon-ids-in-path
Stack Exchange API path parameters for IDs use semicolon-delimited format
$.paths[*]~
info
stack-exchange-wrapper-response
Stack Exchange API responses should use the wrapper envelope format
$.paths[*][get,post,put,patch,delete].responses.200.content.application/json.schema
warn
stack-exchange-pagination-parameters
Stack Exchange list operations should support page and pagesize parameters
$.paths[*].get.parameters[*]
error
stack-exchange-oauth2-defined
Stack Exchange API must define OAuth 2.0 security scheme
$.components.securitySchemes
warn
stack-exchange-tags-defined
All tags referenced in operations must be defined at document level
$.paths[*][get,post,put,patch,delete].tags

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  stack-exchange-operation-summaries-title-case:
    description: All Stack Exchange API operation summaries must use Title Case
    message: "Operation summary '{{value}}' must use Title Case"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9]*([ ][A-Z][a-zA-Z0-9]*)*$"

  stack-exchange-site-parameter-required:
    description: Stack Exchange API endpoints must require the site query parameter
    message: "Operation must include the 'site' query parameter"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].parameters[*]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object

  stack-exchange-operationid-camel-case:
    description: Stack Exchange API operationIds must use camelCase
    message: "operationId '{{value}}' must use camelCase"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  stack-exchange-operations-must-have-operationid:
    description: All Stack Exchange API operations must have an operationId
    message: "Operation is missing operationId"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  stack-exchange-semicolon-ids-in-path:
    description: Stack Exchange API path parameters for IDs use semicolon-delimited format
    message: "Path {ids} parameters accept semicolon-delimited lists of IDs"
    severity: info
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^/[a-z][a-z-/{}]*$"

  stack-exchange-wrapper-response:
    description: Stack Exchange API responses should use the wrapper envelope format
    message: "Response should use Stack Exchange wrapper format with items and has_more"
    severity: info
    given: "$.paths[*][get,post,put,patch,delete].responses.200.content.application/json.schema"
    then:
      function: schema
      functionOptions:
        schema:
          type: object

  stack-exchange-pagination-parameters:
    description: Stack Exchange list operations should support page and pagesize parameters
    message: "List operations should support page and pagesize parameters"
    severity: warn
    given: "$.paths[*].get.parameters[*]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object

  stack-exchange-oauth2-defined:
    description: Stack Exchange API must define OAuth 2.0 security scheme
    message: "Stack Exchange API spec must define oauth2 security scheme"
    severity: error
    given: "$.components.securitySchemes"
    then:
      field: oauth2
      function: truthy

  stack-exchange-tags-defined:
    description: All tags referenced in operations must be defined at document level
    message: "Tags must be defined in the global tags list"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].tags"
    then:
      function: truthy