Synapse · API Governance Rules

Synapse API Rules

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

8 Rules error 2 warn 4
View Rules File View on GitHub

Rule Categories

synapse

Rules

warn
synapse-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][*].summary
error
synapse-operation-has-operation-id
All operations must have an operationId
$.paths[*][get,post,put,delete,patch]
warn
synapse-matrix-path-prefix
Admin API paths should be prefixed with /v1/ or /v2/
$.paths
warn
synapse-bearer-auth-required
All Admin API operations require Bearer token authentication
$.paths[*][get,post,put,delete,patch]
warn
synapse-error-response-defined
Operations should define error responses
$.paths[*][get,post,put,delete,patch].responses
hint
synapse-matrix-user-id-format
Matrix user IDs should follow @localpart:domain format
$.components.schemas.*.properties.name
hint
synapse-pagination-token
List operations should support pagination parameters
$.paths[*][get].parameters[?(@.name == 'limit')]
error
synapse-response-200-defined
All operations must define a success response
$.paths[*][get,post,put,delete,patch].responses

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:

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

  synapse-operation-has-operation-id:
    description: All operations must have an operationId
    message: Operation is missing operationId
    severity: error
    given: "$.paths[*][get,post,put,delete,patch]"
    then:
      field: operationId
      function: truthy

  synapse-matrix-path-prefix:
    description: Admin API paths should be prefixed with /v1/ or /v2/
    message: "Path '{{property}}' should start with a version prefix (e.g. /v1/)"
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^\\/v[0-9]"

  synapse-bearer-auth-required:
    description: All Admin API operations require Bearer token authentication
    message: Operation should reference BearerAuth security scheme
    severity: warn
    given: "$.paths[*][get,post,put,delete,patch]"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["security"]
            - type: object

  synapse-error-response-defined:
    description: Operations should define error responses
    message: Operation is missing error response definitions
    severity: warn
    given: "$.paths[*][get,post,put,delete,patch].responses"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["400"]
            - required: ["401"]
            - required: ["403"]
            - required: ["404"]

  synapse-matrix-user-id-format:
    description: Matrix user IDs should follow @localpart:domain format
    message: User ID parameters should document Matrix user ID format
    severity: hint
    given: "$.components.schemas.*.properties.name"
    then:
      field: description
      function: truthy

  synapse-pagination-token:
    description: List operations should support pagination parameters
    message: List operations should include limit and from pagination parameters
    severity: hint
    given: "$.paths[*][get].parameters[?(@.name == 'limit')]"
    then:
      field: schema
      function: truthy

  synapse-response-200-defined:
    description: All operations must define a success response
    message: Operation is missing a success response
    severity: error
    given: "$.paths[*][get,post,put,delete,patch].responses"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["200"]
            - required: ["201"]
            - required: ["204"]