Tuya · API Governance Rules

Tuya API Rules

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

12 Rules error 4 warn 7
View Rules File View on GitHub

Rule Categories

tuya

Rules

error
tuya-versioned-paths
All API paths must begin with a version segment like /v1.0/
$.paths[*]~
warn
tuya-snake-case-parameters
Parameter names must use snake_case
$.paths[*][*].parameters[*].name
error
tuya-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
tuya-operation-id-camel-case
Operation IDs must use camelCase
$.paths[*][get,post,put,patch,delete].operationId
error
tuya-operation-summary-required
All operations must have a summary
$.paths[*][get,post,put,patch,delete]
warn
tuya-summary-title-case
Operation summaries must use Title Case
$.paths[*][get,post,put,patch,delete].summary
hint
tuya-response-success-field
All 200 responses should include a success field in their schema
$.paths[*][*].responses.200.content.application/json.schema.properties
warn
tuya-operation-description-required
All operations must have a description
$.paths[*][get,post,put,patch,delete]
warn
tuya-operation-tags-required
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete]
warn
tuya-security-scheme-apikey
API must define a tuyaApiKey or equivalent apiKey security scheme
$.components.securitySchemes
error
tuya-servers-defined
At least one server must be defined
$
warn
tuya-tags-title-case
All tags in info must use Title Case
$.tags[*].name

Spectral Ruleset

tuya-rules.yml Raw ↑
extends:
  - spectral:oas

rules:
  # Tuya uses /v{version}/ prefix on all paths
  tuya-versioned-paths:
    description: All API paths must begin with a version segment like /v1.0/
    message: "Path '{{path}}' must begin with /v1.0/ or /v{version}/"
    severity: error
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^/v[0-9]+\\.[0-9]+/"

  # Tuya uses snake_case for path parameters and query parameters
  tuya-snake-case-parameters:
    description: Parameter names must use snake_case
    message: "Parameter '{{value}}' must use snake_case"
    severity: warn
    given: "$.paths[*][*].parameters[*].name"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

  # All operations must have an operationId
  tuya-operation-id-required:
    description: All operations must have an operationId
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: defined

  # All operationIds must be camelCase
  tuya-operation-id-camel-case:
    description: Operation IDs 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]*$"

  # All operations must have a summary
  tuya-operation-summary-required:
    description: All operations must have a summary
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: summary
      function: defined

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

  # Tuya API responses use a standard wrapper with result, success, and t fields
  tuya-response-success-field:
    description: All 200 responses should include a success field in their schema
    severity: hint
    given: "$.paths[*][*].responses.200.content.application/json.schema.properties"
    then:
      field: success
      function: defined

  # Require description on all operations
  tuya-operation-description-required:
    description: All operations must have a description
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: description
      function: defined

  # Require tags on all operations
  tuya-operation-tags-required:
    description: All operations must have at least one tag
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: defined

  # Tuya uses apiKey authentication via client_id header
  tuya-security-scheme-apikey:
    description: API must define a tuyaApiKey or equivalent apiKey security scheme
    severity: warn
    given: "$.components.securitySchemes"
    then:
      function: defined

  # Require servers
  tuya-servers-defined:
    description: At least one server must be defined
    severity: error
    given: "$"
    then:
      field: servers
      function: defined

  # Tags must use Title Case
  tuya-tags-title-case:
    description: All tags in info must use Title Case
    severity: warn
    given: "$.tags[*].name"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"