SonarQube · API Governance Rules

SonarQube API Rules

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

9 Rules error 2 warn 4 info 3
View Rules File View on GitHub

Rule Categories

sonarqube

Rules

warn
sonarqube-operation-summary-title-case
All operation summaries must use Title Case
$.paths[*][*].summary
error
sonarqube-operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete]
warn
sonarqube-tags-required
All operations must be tagged
$.paths[*][get,post,put,patch,delete]
error
sonarqube-200-response-for-get
All GET operations must define a 200 response
$.paths[*].get.responses
warn
sonarqube-security-on-protected-routes
Non-public endpoints must define security requirements
$.paths[*][get,post,put,patch,delete]
info
sonarqube-paging-params-on-list
List/search operations should support pagination parameters
$.paths[*search*].get.parameters[*].name
warn
sonarqube-response-schema-defined
Successful GET responses should have schemas defined
$.paths[*].get.responses[200].content
info
sonarqube-form-encoded-post
SonarQube POST endpoints use form-encoded bodies
$.paths[*].post.requestBody.content
info
sonarqube-component-key-param
Component-scoped endpoints should use 'component' or 'project' parameter
$.paths[*].get.parameters[*].name

Spectral Ruleset

Raw ↑
rules:
  sonarqube-operation-summary-title-case:
    description: All operation summaries must use Title Case
    message: Operation summary "{{value}}" must use Title Case
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-z]*(\\s[A-Z][a-z]*)*$"

  sonarqube-operation-id-required:
    description: All operations must have an operationId
    message: Operation must have an operationId
    severity: error
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  sonarqube-tags-required:
    description: All operations must be tagged
    message: Operation must have at least one tag
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  sonarqube-200-response-for-get:
    description: All GET operations must define a 200 response
    message: GET operation must have a 200 response defined
    severity: error
    given: "$.paths[*].get.responses"
    then:
      field: "200"
      function: truthy

  sonarqube-security-on-protected-routes:
    description: Non-public endpoints must define security requirements
    message: Protected operation must define security schemes
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: security
      function: truthy

  sonarqube-paging-params-on-list:
    description: List/search operations should support pagination parameters
    message: Search/list operations should include 'p' and 'ps' pagination parameters
    severity: info
    given: "$.paths[*search*].get.parameters[*].name"
    then:
      function: enumeration
      functionOptions:
        values: [q, p, ps, filter, f]

  sonarqube-response-schema-defined:
    description: Successful GET responses should have schemas defined
    message: Response 200 should include a content schema
    severity: warn
    given: "$.paths[*].get.responses[200].content"
    then:
      function: truthy

  sonarqube-form-encoded-post:
    description: SonarQube POST endpoints use form-encoded bodies
    message: >-
      SonarQube API POST endpoints use application/x-www-form-urlencoded,
      not application/json
    severity: info
    given: "$.paths[*].post.requestBody.content"
    then:
      function: truthy

  sonarqube-component-key-param:
    description: Component-scoped endpoints should use 'component' or 'project' parameter
    message: Component-scoped operations should use 'component' or 'project' parameter name
    severity: info
    given: "$.paths[*].get.parameters[*].name"
    then:
      function: enumeration
      functionOptions:
        values: [component, project, componentKeys, projectKey, key]