Suger · API Governance Rules

Suger API Rules

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

9 Rules error 3 warn 6
View Rules File View on GitHub

Rule Categories

suger

Rules

error
suger-org-scoped-paths
All Suger API paths must be scoped to an organization via /org/{orgId}
$.paths
warn
suger-operation-id-pascal-case
Suger operationIds must use PascalCase
$.paths[*][*].operationId
error
suger-operation-summary-required
All Suger API operations must have a summary
$.paths[*][get,post,put,patch,delete]
warn
suger-operation-tags-required
All Suger API operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
error
suger-operation-id-required
All Suger API operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
suger-security-api-key
Suger API uses APIKeyAuth - all operations must declare security
$.paths[*][get,post,put,patch,delete]
warn
suger-path-param-camel-case
Suger path parameters should use camelCase naming
$.paths[*][*].parameters[?(@.in == 'path')].name
warn
suger-request-body-json
Suger request bodies should use application/json content type
$.paths[*][post,put,patch].requestBody.content
warn
suger-response-schema-defined
Suger API 200 responses should have a schema defined
$.paths[*][get,post,put,patch].responses['200'].content

Spectral Ruleset

Raw ↑
extends: [[spectral:oas, recommended]]

rules:
  # Suger API Convention: All paths must be under /org/{orgId}/
  suger-org-scoped-paths:
    description: All Suger API paths must be scoped to an organization via /org/{orgId}
    message: "{{description}} - path '{{property}}' must start with /org/{orgId}"
    severity: error
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^/org/\\{orgId\\}"

  # Suger uses camelCase for path parameters and operationIds
  suger-operation-id-pascal-case:
    description: Suger operationIds must use PascalCase
    message: "{{description}} - '{{value}}' should be PascalCase"
    severity: warn
    given: "$.paths[*][*].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9]+$"

  # All operations must have summaries
  suger-operation-summary-required:
    description: All Suger API operations must have a summary
    message: "{{description}} - operation is missing a summary"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: summary
      function: truthy

  # All operations must have at least one tag
  suger-operation-tags-required:
    description: All Suger API operations must have at least one tag
    message: "{{description}} - operation is missing tags"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  # All operations must have an operationId
  suger-operation-id-required:
    description: All Suger API operations must have an operationId
    message: "{{description}} - operation is missing an operationId"
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  # Suger uses API key auth - must be declared
  suger-security-api-key:
    description: Suger API uses APIKeyAuth - all operations must declare security
    message: "{{description}} - operation should declare security requirements"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: security
      function: truthy

  # Path parameters must use camelCase
  suger-path-param-camel-case:
    description: Suger path parameters should use camelCase naming
    message: "{{description}} - path parameter '{{value}}' should use camelCase"
    severity: warn
    given: "$.paths[*][*].parameters[?(@.in == 'path')].name"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

  # Request bodies should have application/json content type
  suger-request-body-json:
    description: Suger request bodies should use application/json content type
    message: "{{description}} - request body should use application/json"
    severity: warn
    given: "$.paths[*][post,put,patch].requestBody.content"
    then:
      function: pattern
      functionOptions:
        match: "application/json"

  # Response schemas should be defined
  suger-response-schema-defined:
    description: Suger API 200 responses should have a schema defined
    message: "{{description}} - 200 response should have a schema"
    severity: warn
    given: "$.paths[*][get,post,put,patch].responses['200'].content"
    then:
      function: truthy