Terapi · API Governance Rules

Terapi API Rules

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

20 Rules error 8 warn 12
View Rules File View on GitHub

Rule Categories

terapi

Rules

error
terapi-security-apikey
Terapi API must use API key (secret key) authentication
$
warn
terapi-path-resource-style
Terapi API paths use noun-based resource names
$.paths[*]~
warn
terapi-path-no-trailing-slash
Paths must not have trailing slashes
$.paths[*]~
warn
terapi-list-get-method
List operations should use GET method
$.paths[*][get].operationId
warn
terapi-create-post-method
Create operations should use POST
$.paths[*][post].operationId
error
terapi-delete-method
Delete operations must use DELETE
$.paths[*][delete].operationId
error
terapi-get-200-response
GET operations must return 200
$.paths[*][get].responses
warn
terapi-delete-204-response
DELETE operations should return 204
$.paths[*][delete].responses
error
terapi-401-response
All authenticated operations must define 401
$.paths[*][get,post,put,patch,delete].responses
warn
terapi-404-for-resource
Resource operations with ID parameters should define 404
$.paths[*~'/{[^}]+}'][get,delete].responses
warn
terapi-provider-config-key-required
Operations using provider_config_key should mark it required
$.paths[*][*].parameters[?(@.name == 'provider_config_key')]
error
terapi-connection-id-required
Path parameter connection_id must be required
$.paths[*][*].parameters[?(@.name == 'connection_id' && @.in == 'path')]
error
terapi-operation-id
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
error
terapi-operation-summary
All operations must have a summary
$.paths[*][get,post,put,patch,delete]
warn
terapi-summary-title-case
Summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
warn
terapi-operation-description
Operations should have descriptions
$.paths[*][get,post,put,patch,delete]
error
terapi-tags
Operations must have tags
$.paths[*][get,post,put,patch,delete]
warn
terapi-schema-descriptions
Schema components should have descriptions
$.components.schemas[*]
warn
terapi-connection-id-string
Connection IDs should always be string type
$.components.schemas[*].properties.id
warn
terapi-input-object
Action trigger input should be an object
$.components.schemas.TriggerActionRequest.properties.input

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Authentication
  terapi-security-apikey:
    description: Terapi API must use API key (secret key) authentication
    message: "Terapi API must define global API key security"
    given: "$"
    then:
      field: security
      function: truthy
    severity: error

  # Path Conventions
  terapi-path-resource-style:
    description: Terapi API paths use noun-based resource names
    message: "Path '{{property}}' should use resource nouns (connection, integration, sync, action, auth)"
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^/(connection|integration|sync|action|auth)"
    severity: warn

  terapi-path-no-trailing-slash:
    description: Paths must not have trailing slashes
    message: "Path '{{property}}' must not have a trailing slash"
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"
    severity: warn

  # HTTP Methods
  terapi-list-get-method:
    description: List operations should use GET method
    message: "List operations should use GET"
    given: "$.paths[*][get].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^(list|get)[A-Z]"
    severity: warn

  terapi-create-post-method:
    description: Create operations should use POST
    message: "Create/trigger operations should use POST"
    given: "$.paths[*][post].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^(create|trigger)[A-Z]"
    severity: warn

  terapi-delete-method:
    description: Delete operations must use DELETE
    message: "Delete operations must use DELETE"
    given: "$.paths[*][delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^delete[A-Z]"
    severity: error

  # Response Codes
  terapi-get-200-response:
    description: GET operations must return 200
    message: "GET operations must define a 200 response"
    given: "$.paths[*][get].responses"
    then:
      field: "200"
      function: truthy
    severity: error

  terapi-delete-204-response:
    description: DELETE operations should return 204
    message: "DELETE operations should return 204 No Content"
    given: "$.paths[*][delete].responses"
    then:
      field: "204"
      function: truthy
    severity: warn

  terapi-401-response:
    description: All authenticated operations must define 401
    message: "All operations must define 401 Unauthorized response"
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "401"
      function: truthy
    severity: error

  terapi-404-for-resource:
    description: Resource operations with ID parameters should define 404
    message: "Resource operations should define 404 Not Found"
    given: "$.paths[*~'/{[^}]+}'][get,delete].responses"
    then:
      field: "404"
      function: truthy
    severity: warn

  # Parameters
  terapi-provider-config-key-required:
    description: Operations using provider_config_key should mark it required
    message: "provider_config_key parameter should be required"
    given: "$.paths[*][*].parameters[?(@.name == 'provider_config_key')]"
    then:
      field: required
      function: truthy
    severity: warn

  terapi-connection-id-required:
    description: Path parameter connection_id must be required
    message: "Path parameter connection_id must be marked required"
    given: "$.paths[*][*].parameters[?(@.name == 'connection_id' && @.in == 'path')]"
    then:
      field: required
      function: truthy
    severity: error

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

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

  terapi-summary-title-case:
    description: Summaries must use Title Case
    message: "Summary '{{value}}' must use Title Case (start with capital letter)"
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"
    severity: warn

  terapi-operation-description:
    description: Operations should have descriptions
    message: "Operation is missing a description"
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: description
      function: truthy
    severity: warn

  terapi-tags:
    description: Operations must have tags
    message: "Operation is missing tags"
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy
    severity: error

  # Schema Conventions
  terapi-schema-descriptions:
    description: Schema components should have descriptions
    message: "Schema component '{{path}}' is missing a description"
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy
    severity: warn

  terapi-connection-id-string:
    description: Connection IDs should always be string type
    message: "Connection ID fields should be type: string"
    given: "$.components.schemas[*].properties.id"
    then:
      field: type
      function: enumeration
      functionOptions:
        values:
          - string
    severity: warn

  # Webhook/Event Consistency
  terapi-input-object:
    description: Action trigger input should be an object
    message: "Action input should be type: object"
    given: "$.components.schemas.TriggerActionRequest.properties.input"
    then:
      field: type
      function: enumeration
      functionOptions:
        values:
          - object
    severity: warn