Tripadvisor · API Governance Rules

Tripadvisor API Rules

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

9 Rules error 2 warn 7
View Rules File View on GitHub

Rule Categories

tripadvisor

Rules

warn
tripadvisor-path-versioned
Tripadvisor Content API paths must use /api/v1/ prefix
$.paths[*]~
warn
tripadvisor-operation-id-camel-case
OperationIds must use camelCase
$.paths[*][*].operationId
error
tripadvisor-summary-title-case
Operation summaries must use Title Case
$.paths[*][*].summary
error
tripadvisor-get-must-have-200
GET operations must define a 200 response
$.paths[*].get
warn
tripadvisor-must-have-400-response
All operations must document a 400 Bad Request response
$.paths[*][get,post,put,delete].responses
warn
tripadvisor-must-have-401-response
All operations must document 401 Unauthorized response
$.paths[*][get,post,put,delete].responses
warn
tripadvisor-operation-must-have-description
All operations must have a description
$.paths[*][get,post,put,patch,delete]
warn
tripadvisor-schema-pascal-case
Schema names must use PascalCase
$.components.schemas[*]~
warn
tripadvisor-operations-must-use-defined-tags
Operations should use tags defined in the top-level tags array
$.paths[*][*].tags[*]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Content API must use /api/v1/ prefix
  tripadvisor-path-versioned:
    description: Tripadvisor Content API paths must use /api/v1/ prefix
    message: "Path '{{property}}' should start with /api/v1/"
    given: "$.paths[*]~"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^/(api/v1|v[0-9]+)/"

  # All operations must have operationIds in camelCase
  tripadvisor-operation-id-camel-case:
    description: OperationIds must use camelCase
    message: "OperationId '{{value}}' should use camelCase"
    given: "$.paths[*][*].operationId"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"

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

  # All GET operations must have a 200 response
  tripadvisor-get-must-have-200:
    description: GET operations must define a 200 response
    message: "GET operation is missing a 200 response"
    given: "$.paths[*].get"
    severity: error
    then:
      field: responses.200
      function: truthy

  # All operations must have a 400 response for error handling
  tripadvisor-must-have-400-response:
    description: All operations must document a 400 Bad Request response
    message: "Operation is missing 400 response definition"
    given: "$.paths[*][get,post,put,delete].responses"
    severity: warn
    then:
      field: "400"
      function: truthy

  # All operations must have a 401 response for unauthorized
  tripadvisor-must-have-401-response:
    description: All operations must document 401 Unauthorized response
    message: "Operation is missing 401 response definition"
    given: "$.paths[*][get,post,put,delete].responses"
    severity: warn
    then:
      field: "401"
      function: truthy

  # All operations must have descriptions
  tripadvisor-operation-must-have-description:
    description: All operations must have a description
    message: "Operation at '{{path}}' is missing a description"
    given: "$.paths[*][get,post,put,patch,delete]"
    severity: warn
    then:
      field: description
      function: truthy

  # Schema component names must use PascalCase
  tripadvisor-schema-pascal-case:
    description: Schema names must use PascalCase
    message: "Schema '{{property}}' should use PascalCase"
    given: "$.components.schemas[*]~"
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9]+$"

  # Tags must be defined in the top-level tags list
  tripadvisor-operations-must-use-defined-tags:
    description: Operations should use tags defined in the top-level tags array
    message: "Tag '{{value}}' used in operation but not defined at top level"
    given: "$.paths[*][*].tags[*]"
    severity: warn
    then:
      function: truthy