TheGamesDB · API Governance Rules

TheGamesDB API Rules

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

22 Rules error 8 warn 10 info 4
View Rules File View on GitHub

Rule Categories

get info no openapi operation parameter paths response schema servers

Rules

error
info-title-required
Info object must have a title
$.info
warn
info-description-required
Info object must have a description
$.info
error
info-version-required
API version must be defined
$.info
warn
openapi-version-3
OpenAPI version should be 3.x
$
error
servers-defined
Servers array must be defined
$
error
servers-https
Server URLs must use HTTPS
$.servers[*].url
warn
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths[*]~
info
paths-versioned
Paths should include a version prefix
$.paths[*]~
error
operation-summary-required
Operations must have a summary
$.paths[*][get,post,put,delete,patch]
warn
operation-description-required
Operations must have a description
$.paths[*][get,post,put,delete,patch]
error
operation-operationId-required
Operations must have an operationId
$.paths[*][get,post,put,delete,patch]
warn
operation-tags-required
Operations must have at least one tag
$.paths[*][get,post,put,delete,patch]
info
operation-summary-provider-prefix
Operation summaries should start with 'TheGamesDB'
$.paths[*][get,post,put,delete,patch].summary
warn
parameter-apikey-required-in-query
TheGamesDB requires apikey query parameter on all operations
$.paths[*][get,post,put,delete,patch].parameters[?(@.name=='apikey')]
warn
parameter-description-required
Parameters must have descriptions
$.paths[*][get,post,put,delete,patch].parameters[*]
info
parameter-pagination-page
Paginated endpoints should use 'page' parameter name
$.paths[*][get].parameters[?(@.name=='offset')]
error
response-success-required
Operations must have at least one success response
$.paths[*][get,post,put,delete,patch].responses
info
response-400-for-query-endpoints
Query endpoints should document 400 bad input response
$.paths[*][get].responses
warn
response-403-for-api-key
TheGamesDB endpoints should document 403 invalid key response
$.paths[*][get].responses
warn
schema-type-defined
Schema objects should have a type
$.components.schemas[*]
error
get-no-request-body
GET operations must not have a request body
$.paths[*].get
warn
no-empty-descriptions
Descriptions must not be empty
$..description

Spectral Ruleset

Raw ↑
rules:

  # INFO / METADATA
  info-title-required:
    description: Info object must have a title
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  info-description-required:
    description: Info object must have a description
    severity: warn
    given: $.info
    then:
      field: description
      function: truthy

  info-version-required:
    description: API version must be defined
    severity: error
    given: $.info
    then:
      field: version
      function: truthy

  # OPENAPI VERSION
  openapi-version-3:
    description: OpenAPI version should be 3.x
    severity: warn
    given: $
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: "^3\\."

  # SERVERS
  servers-defined:
    description: Servers array must be defined
    severity: error
    given: $
    then:
      field: servers
      function: truthy

  servers-https:
    description: Server URLs must use HTTPS
    severity: error
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  # PATHS
  paths-no-trailing-slash:
    description: Paths must not have trailing slashes
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  paths-versioned:
    description: Paths should include a version prefix
    severity: info
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^/v[0-9]"

  # OPERATIONS
  operation-summary-required:
    description: Operations must have a summary
    severity: error
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: summary
      function: truthy

  operation-description-required:
    description: Operations must have a description
    severity: warn
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: description
      function: truthy

  operation-operationId-required:
    description: Operations must have an operationId
    severity: error
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: operationId
      function: truthy

  operation-tags-required:
    description: Operations must have at least one tag
    severity: warn
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: tags
      function: truthy

  operation-summary-provider-prefix:
    description: Operation summaries should start with 'TheGamesDB'
    severity: info
    given: $.paths[*][get,post,put,delete,patch].summary
    then:
      function: pattern
      functionOptions:
        match: "^TheGamesDB "

  # PARAMETERS
  parameter-apikey-required-in-query:
    description: TheGamesDB requires apikey query parameter on all operations
    severity: warn
    given: $.paths[*][get,post,put,delete,patch].parameters[?(@.name=='apikey')]
    then:
      field: required
      function: truthy

  parameter-description-required:
    description: Parameters must have descriptions
    severity: warn
    given: $.paths[*][get,post,put,delete,patch].parameters[*]
    then:
      field: description
      function: truthy

  parameter-pagination-page:
    description: Paginated endpoints should use 'page' parameter name
    severity: info
    given: $.paths[*][get].parameters[?(@.name=='offset')]
    then:
      field: name
      function: enumeration
      functionOptions:
        values:
          - page

  # RESPONSES
  response-success-required:
    description: Operations must have at least one success response
    severity: error
    given: $.paths[*][get,post,put,delete,patch].responses
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          minProperties: 1

  response-400-for-query-endpoints:
    description: Query endpoints should document 400 bad input response
    severity: info
    given: $.paths[*][get].responses
    then:
      field: "400"
      function: defined

  response-403-for-api-key:
    description: TheGamesDB endpoints should document 403 invalid key response
    severity: warn
    given: $.paths[*][get].responses
    then:
      field: "403"
      function: defined

  # SCHEMAS
  schema-type-defined:
    description: Schema objects should have a type
    severity: warn
    given: $.components.schemas[*]
    then:
      field: type
      function: truthy

  # HTTP METHODS
  get-no-request-body:
    description: GET operations must not have a request body
    severity: error
    given: $.paths[*].get
    then:
      field: requestBody
      function: falsy

  # GENERAL QUALITY
  no-empty-descriptions:
    description: Descriptions must not be empty
    severity: warn
    given: $..description
    then:
      function: pattern
      functionOptions:
        match: ".+"