Varonis · API Governance Rules

Varonis API Rules

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

34 Rules error 13 warn 20 info 1
View Rules File View on GitHub

Rule Categories

get info no openapi operation parameter paths post request response schema security servers tags

Rules

error
info-title-required
API title must be present and non-empty.
$.info
warn
info-title-starts-with-varonis
API title should start with "Varonis".
$.info.title
warn
info-description-required
API description must be present and non-empty.
$.info
error
info-version-required
API version must be specified.
$.info
warn
info-contact-required
Contact information should be present.
$.info
error
openapi-version-3x
API specification must use OpenAPI 3.x.
$
error
servers-required
At least one server must be defined.
$
error
servers-https-required
Server URLs must use HTTPS.
$.servers[*].url
warn
servers-description-required
Each server should have a description.
$.servers[*]
error
operation-operationId-required
All operations must have an operationId.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-operationId-camelCase
operationId must 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-varonis
Operation summaries should start with "Varonis".
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
All operations must have a description.
$.paths[*][get,post,put,patch,delete,options,head]
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
tags-description-required
Each global tag should have a description.
$.tags[*]
warn
parameter-description-required
All parameters must have a description.
$..parameters[*]
error
parameter-schema-type-required
All parameters must have a schema with a type.
$..parameters[*].schema
warn
request-body-description-required
Request bodies should have a description.
$.paths[*][post,put,patch].requestBody
warn
request-body-content-json
POST/PUT/PATCH operations should accept application/json.
$.paths[*][post,put,patch].requestBody.content
error
response-success-required
Operations must define at least one success (2xx) response.
$.paths[*][get,post,put,patch,delete].responses
warn
response-400-for-post
POST operations with request bodies should define 400 Bad Request.
$.paths[*].post.responses
warn
response-401-required
Operations should define 401 Unauthorized.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
All responses must have a description.
$.paths[*][*].responses[*]
warn
schema-property-description-required
Top-level schema definitions should have a description.
$.components.schemas[*]
warn
schema-properties-have-types
Schema properties should have explicit types.
$.components.schemas[*].properties[*]
error
security-schemes-defined
Security schemes must be defined in components.
$.components
warn
security-global-defined
Global security should be defined.
$
error
security-apikey-header-not-query
API keys should be passed in headers, not query parameters.
$.components.securitySchemes[?(@.type == 'apiKey')]
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
info
post-should-have-request-body
POST operations should typically have a request body.
$.paths[*].post
warn
no-empty-description
Descriptions must not be empty strings.
$..description
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths

Spectral Ruleset

Raw ↑
rules:

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

  info-title-starts-with-varonis:
    description: API title should start with "Varonis".
    severity: warn
    given: "$.info.title"
    then:
      function: pattern
      functionOptions:
        match: "^Varonis"

  info-description-required:
    description: API description must be present and non-empty.
    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

  info-contact-required:
    description: Contact information should be present.
    severity: warn
    given: "$.info"
    then:
      field: contact
      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: At least one server 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://"

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

  # 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 must 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-varonis:
    description: Operation summaries should start with "Varonis".
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^Varonis "

  operation-description-required:
    description: All operations must have a description.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete,options,head]"
    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

  tags-description-required:
    description: Each global 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: warn
    given: "$..parameters[*]"
    then:
      field: description
      function: truthy

  parameter-schema-type-required:
    description: All parameters must have a schema with a type.
    severity: error
    given: "$..parameters[*].schema"
    then:
      field: type
      function: truthy

  # REQUEST BODIES
  request-body-description-required:
    description: Request bodies should have a description.
    severity: warn
    given: "$.paths[*][post,put,patch].requestBody"
    then:
      field: description
      function: truthy

  request-body-content-json:
    description: POST/PUT/PATCH operations should accept application/json.
    severity: warn
    given: "$.paths[*][post,put,patch].requestBody.content"
    then:
      field: application/json
      function: truthy

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

  response-400-for-post:
    description: POST operations with request bodies should define 400 Bad Request.
    severity: warn
    given: "$.paths[*].post.responses"
    then:
      field: '400'
      function: truthy

  response-401-required:
    description: Operations should define 401 Unauthorized.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: '401'
      function: truthy

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

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

  schema-properties-have-types:
    description: Schema properties should have explicit types.
    severity: warn
    given: "$.components.schemas[*].properties[*]"
    then:
      field: type
      function: truthy

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

  security-global-defined:
    description: Global security should be defined.
    severity: warn
    given: "$"
    then:
      field: security
      function: truthy

  security-apikey-header-not-query:
    description: API keys should be passed in headers, not query parameters.
    severity: error
    given: "$.components.securitySchemes[?(@.type == 'apiKey')]"
    then:
      field: in
      function: pattern
      functionOptions:
        match: "^header$"

  # 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

  post-should-have-request-body:
    description: POST operations should typically have a request body.
    severity: info
    given: "$.paths[*].post"
    then:
      field: requestBody
      function: truthy

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

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