The Racing API · API Governance Rules

The Racing API API Rules

Spectral linting rules defining API design standards and conventions for The Racing API.

28 Rules error 9 warn 11 info 8
View Rules File View on GitHub

Rule Categories

get info no openapi operation parameter paths response schema security servers

Rules

error
info-title-required
Info object must have a title
$.info
warn
info-description-required
Info object must have a description with minimum length
$.info
error
info-version-required
API version must be defined
$.info
warn
openapi-version-31
OpenAPI version should be 3.1.x
$
error
servers-defined
Servers array must be defined and non-empty
$
error
servers-https
Server URLs must use HTTPS
$.servers[*].url
warn
paths-kebab-case
Path segments must use kebab-case
$.paths[*]~
warn
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths[*]~
info
paths-versioned
Paths should include version prefix /v1/
$.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 'The Racing API'
$.paths[*][get,post,put,delete,patch].summary
warn
parameter-description-required
Parameters must have descriptions
$.paths[*][get,post,put,delete,patch].parameters[*]
info
parameter-snake-case
Query parameter names should use snake_case
$.paths[*][get,post,put,delete,patch].parameters[?(@.in=='query')].name
warn
parameter-apikey-not-in-query
API keys should be in headers not query parameters
$.paths[*][get,post,put,delete,patch].parameters[?(@.name=='api_key' || @.name=='apikey')]
error
response-success-required
Operations must have at least one 2xx response
$.paths[*][get,post,put,delete,patch].responses
warn
response-description-required
Response objects must have a description
$.paths[*][get,post,put,delete,patch].responses[*]
info
response-404-for-id-paths
Endpoints with path parameters should have a 404 response
$.paths[~*{*}*][get].responses
info
response-422-validation-error
The Racing API uses 422 for validation errors
$.paths[*][get,post,put,delete,patch].responses
warn
schema-type-defined
Schema objects should have a type defined
$.components.schemas[*]
info
schema-description-required
Top-level schemas should have a description
$.components.schemas[*]
error
security-schemes-defined
Security schemes must be defined in components
$.components
info
security-basic-auth
The Racing API uses HTTP Basic authentication
$.components.securitySchemes[*]
error
get-no-request-body
GET operations must not have a request body
$.paths[*].get
warn
no-empty-descriptions
Descriptions must not be empty strings
$..description
info
operation-examples-encouraged
Operations should have examples for mock server compatibility
$.paths[*][get,post,put,delete,patch].responses[*].content[*]

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 with minimum length
    severity: warn
    given: $.info
    then:
      field: description
      function: minLength
      functionOptions:
        value: 20

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

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

  # SERVERS
  servers-defined:
    description: Servers array must be defined and non-empty
    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 — NAMING CONVENTIONS
  paths-kebab-case:
    description: Path segments must use kebab-case
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^(/v[0-9]+)?(/[a-z0-9]+(-[a-z0-9]+)*(/{[a-z_]+})?)*$"

  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 version prefix /v1/
    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 'The Racing API'
    severity: info
    given: $.paths[*][get,post,put,delete,patch].summary
    then:
      function: pattern
      functionOptions:
        match: "^The Racing API "

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

  parameter-snake-case:
    description: Query parameter names should use snake_case
    severity: info
    given: $.paths[*][get,post,put,delete,patch].parameters[?(@.in=='query')].name
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

  parameter-apikey-not-in-query:
    description: API keys should be in headers not query parameters
    severity: warn
    given: $.paths[*][get,post,put,delete,patch].parameters[?(@.name=='api_key' || @.name=='apikey')]
    then:
      field: in
      function: enumeration
      functionOptions:
        values:
          - header

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

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

  response-404-for-id-paths:
    description: Endpoints with path parameters should have a 404 response
    severity: info
    given: $.paths[~*{*}*][get].responses
    then:
      field: "404"
      function: truthy

  response-422-validation-error:
    description: The Racing API uses 422 for validation errors
    severity: info
    given: $.paths[*][get,post,put,delete,patch].responses
    then:
      field: "422"
      function: defined

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

  schema-description-required:
    description: Top-level schemas should have a description
    severity: info
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy

  # SECURITY
  security-schemes-defined:
    description: Security schemes must be defined in components
    severity: error
    given: $.components
    then:
      field: securitySchemes
      function: truthy

  security-basic-auth:
    description: The Racing API uses HTTP Basic authentication
    severity: info
    given: $.components.securitySchemes[*]
    then:
      field: type
      function: enumeration
      functionOptions:
        values:
          - http

  # HTTP METHOD CONVENTIONS
  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 strings
    severity: warn
    given: $..description
    then:
      function: pattern
      functionOptions:
        match: ".+"

  operation-examples-encouraged:
    description: Operations should have examples for mock server compatibility
    severity: info
    given: $.paths[*][get,post,put,delete,patch].responses[*].content[*]
    then:
      field: examples
      function: defined