HashiCorp Vault · API Governance Rules

HashiCorp Vault API Rules

Spectral linting rules defining API design standards and conventions for HashiCorp Vault.

28 Rules error 11 warn 12 info 5
View Rules File View on GitHub

Rule Categories

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

Rules

error
info-title-required
API title must be present.
$.info
warn
info-title-starts-with-hashicorp-vault
API title should start with "HashiCorp Vault".
$.info.title
warn
info-description-required
API info description must be present.
$.info
error
info-version-required
API version must be specified.
$.info
error
openapi-version-3x
API specification must use OpenAPI 3.x.
$
error
servers-required
Servers array must be defined.
$
error
servers-https-required
Server URLs must use HTTPS.
$.servers[*].url
info
paths-v1-prefix
All Vault API paths begin at the server level v1 — paths should be relative.
$.paths
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths
error
operation-operationId-required
All operations must have an operationId.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-operationId-camelCase
operationId should use camelCase.
$.paths[*][get,post,put,patch,delete].operationId
error
operation-summary-required
All operations must have a summary.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-summary-starts-with-hashicorp-vault
Operation summaries should start with "HashiCorp Vault".
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
All operations should have a description.
$.paths[*][get,post,put,patch,delete]
warn
operation-tags-required
All operations must have at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
tags-global-defined
Global tags array should be defined.
$
warn
parameter-description-required
All parameters should have a description.
$..parameters[*]
error
response-success-required
Operations must define at least one success (2xx or 204) response.
$.paths[*][get,post,put,patch,delete].responses
warn
response-403-required
Vault operations should define 403 Permission Denied response.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
All responses must have a description.
$.paths[*][*].responses[*]
warn
schema-description-required
Schema definitions should have descriptions.
$.components.schemas[*]
info
schema-properties-have-descriptions
Schema properties should have descriptions.
$.components.schemas[*].properties[*]
error
security-schemes-defined
Security schemes must be defined in components.
$.components
info
vault-token-header-not-bearer
Vault uses X-Vault-Token header, not Authorization Bearer.
$.components.securitySchemes[?(@.type == 'apiKey')]
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
info
delete-returns-204
DELETE operations should return 204 No Content.
$.paths[*].delete.responses
warn
no-empty-description
Descriptions must not be empty strings.
$..description
info
operation-has-microcks-extension
Operations should have x-microcks-operation for mock compatibility.
$.paths[*][get,post,put,patch,delete]

Spectral Ruleset

Raw ↑
rules:

  # INFO / METADATA
  info-title-required:
    description: API title must be present.
    severity: error
    given: "$.info"
    then:
      field: title
      function: truthy

  info-title-starts-with-hashicorp-vault:
    description: API title should start with "HashiCorp Vault".
    severity: warn
    given: "$.info.title"
    then:
      function: pattern
      functionOptions:
        match: "^HashiCorp Vault"

  info-description-required:
    description: API info description must be present.
    severity: warn
    given: "$.info"
    then:
      field: description
      function: truthy

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

  # OPENAPI VERSION
  openapi-version-3x:
    description: API specification must use OpenAPI 3.x.
    severity: error
    given: "$"
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: "^3\\."

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

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

  # PATHS
  paths-v1-prefix:
    description: All Vault API paths begin at the server level v1 — paths should be relative.
    severity: info
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        notMatch: "^/v1"

  paths-no-trailing-slash:
    description: Paths must not end with a trailing slash.
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

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

  operation-operationId-camelCase:
    description: operationId should use camelCase.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

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

  operation-summary-starts-with-hashicorp-vault:
    description: Operation summaries should start with "HashiCorp Vault".
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^HashiCorp Vault"

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

  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: truthy

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

  # PARAMETERS
  parameter-description-required:
    description: All parameters should have a description.
    severity: warn
    given: "$..parameters[*]"
    then:
      field: description
      function: truthy

  # RESPONSES
  response-success-required:
    description: Operations must define at least one success (2xx or 204) response.
    severity: error
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ['200']
            - required: ['201']
            - required: ['204']

  response-403-required:
    description: Vault operations should define 403 Permission Denied response.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: '403'
      function: truthy

  response-description-required:
    description: All responses must have a description.
    severity: error
    given: "$.paths[*][*].responses[*]"
    then:
      field: description
      function: truthy

  # SCHEMAS
  schema-description-required:
    description: Schema definitions should have descriptions.
    severity: warn
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy

  schema-properties-have-descriptions:
    description: Schema properties should have descriptions.
    severity: info
    given: "$.components.schemas[*].properties[*]"
    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

  vault-token-header-not-bearer:
    description: Vault uses X-Vault-Token header, not Authorization Bearer.
    severity: info
    given: "$.components.securitySchemes[?(@.type == 'apiKey')]"
    then:
      field: name
      function: pattern
      functionOptions:
        match: "^X-Vault-Token$"

  # 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-returns-204:
    description: DELETE operations should return 204 No Content.
    severity: info
    given: "$.paths[*].delete.responses"
    then:
      field: '204'
      function: truthy

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

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