WattTime · API Governance Rules

WattTime API Rules

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

31 Rules error 13 warn 17 info 1
View Rules File View on GitHub

Rule Categories

delete get info microcks no openapi operation parameter paths response schema security servers tag tags

Rules

error
info-title-required
Info title must be present and non-empty.
$.info
warn
info-title-prefix
API title should start with "WattTime".
$.info
warn
info-description-required
Info description must be present and at least 50 characters.
$.info
error
info-version-required
API version must be defined.
$.info
warn
info-contact-required
Contact information should be provided.
$.info
warn
openapi-version
OpenAPI version must be 3.1.0.
$
error
servers-defined
At least one server must be defined.
$
error
servers-https
All server URLs must use HTTPS.
$.servers[*]
warn
servers-description
Each server should have a description.
$.servers[*]
warn
paths-kebab-case
Path segments must use kebab-case (lowercase with hyphens).
$.paths[*]~
warn
paths-no-trailing-slash
Paths must not have trailing slashes.
$.paths[*]~
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-summary-title-case
Operation summaries should start with "WattTime".
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-description-required
Every operation should have a description.
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-id-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-id-camel-case
operationId must use camelCase.
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete,head,options]
warn
tags-defined
Global tags array should be defined.
$
warn
tag-description
Every tag should have a description.
$.tags[*]
error
parameter-description-required
All parameters must have a description.
$.paths[*][get,post,put,patch,delete][parameters][*]
warn
parameter-snake-case
Query and path parameter names should use snake_case.
$.paths[*][get,post,put,patch,delete][parameters][?(@.in == 'query' || @.in == 'path')]
error
response-success-required
Every operation must have at least one 2xx response.
$.paths[*][get,post,put,patch,delete]
warn
response-401-required
Authenticated operations should define a 401 response.
$.paths[/login,/data,/forecast,/historical,/maps,/my-access,/region-from-loc][get,post]
error
response-description-required
Every response must have a description.
$.paths[*][get,post,put,patch,delete].responses[*]
warn
schema-property-snake-case
Schema property names should use snake_case.
$.components.schemas[*].properties[*]~
warn
schema-description-required
Top-level schemas should have a description.
$.components.schemas[*]
error
security-schemes-defined
Security schemes must be defined in components.
$.components
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
warn
delete-no-request-body
DELETE operations should not have a request body.
$.paths[*].delete
error
no-empty-descriptions
Descriptions must not be empty strings.
$..description
info
microcks-operation-extension
Operations should include x-microcks-operation for mock support.
$.paths[*][get,post,put,patch,delete]

Spectral Ruleset

Raw ↑
rules:
  # INFO / METADATA
  info-title-required:
    description: Info title must be present and non-empty.
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  info-title-prefix:
    description: API title should start with "WattTime".
    severity: warn
    given: $.info
    then:
      field: title
      function: pattern
      functionOptions:
        match: '^WattTime'

  info-description-required:
    description: Info description must be present and at least 50 characters.
    severity: warn
    given: $.info
    then:
      field: description
      function: minLength
      functionOptions:
        value: 50

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

  info-contact-required:
    description: Contact information should be provided.
    severity: warn
    given: $.info
    then:
      field: contact
      function: truthy

  # OPENAPI VERSION
  openapi-version:
    description: OpenAPI version must be 3.1.0.
    severity: warn
    given: $
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: '^3\.1\.'

  # SERVERS
  servers-defined:
    description: At least one server must be defined.
    severity: error
    given: $
    then:
      field: servers
      function: truthy

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

  servers-description:
    description: Each server should have a description.
    severity: warn
    given: $.servers[*]
    then:
      field: description
      function: truthy

  # PATHS — NAMING CONVENTIONS
  paths-kebab-case:
    description: Path segments must use kebab-case (lowercase with hyphens).
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: '^(/[a-z0-9{}-]+)+$'

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

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

  operation-summary-title-case:
    description: Operation summaries should start with "WattTime".
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: summary
      function: pattern
      functionOptions:
        match: '^WattTime '

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

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

  operation-id-camel-case:
    description: operationId must use camelCase.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: operationId
      function: pattern
      functionOptions:
        match: '^[a-z][a-zA-Z0-9]+$'

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

  # TAGS
  tags-defined:
    description: Global tags array should be defined.
    severity: warn
    given: $
    then:
      field: tags
      function: truthy

  tag-description:
    description: Every tag should have a description.
    severity: warn
    given: $.tags[*]
    then:
      field: description
      function: truthy

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

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

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

  response-401-required:
    description: Authenticated operations should define a 401 response.
    severity: warn
    given: $.paths[/login,/data,/forecast,/historical,/maps,/my-access,/region-from-loc][get,post]
    then:
      field: responses
      function: schema
      functionOptions:
        schema:
          type: object
          required:
            - '401'

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

  # SCHEMAS — PROPERTY NAMING
  schema-property-snake-case:
    description: Schema property names should use snake_case.
    severity: warn
    given: $.components.schemas[*].properties[*]~
    then:
      function: pattern
      functionOptions:
        match: '^[a-z][a-z0-9_]*$'

  schema-description-required:
    description: Top-level schemas should have a description.
    severity: warn
    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

  # 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

  delete-no-request-body:
    description: DELETE operations should not have a request body.
    severity: warn
    given: $.paths[*].delete
    then:
      field: requestBody
      function: falsy

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

  microcks-operation-extension:
    description: Operations should include x-microcks-operation for mock support.
    severity: info
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: x-microcks-operation
      function: truthy