Salesforce Einstein · API Governance Rules

Salesforce Einstein API Rules

Spectral linting rules defining API design standards and conventions for Salesforce Einstein.

9 Rules error 6 warn 3
View Rules File View on GitHub

Rule Categories

einstein

Rules

error
einstein-operation-id-required
All operations must have an operationId.
$.paths[*][*]
error
einstein-summary-not-empty
All operations must have a summary.
$.paths[*][*]
warn
einstein-tags-required
All operations must have at least one tag.
$.paths[*][*]
error
einstein-response-200-required
All operations must define a 200 success response.
$.paths[*][*].responses
error
einstein-auth-required
All Einstein APIs require bearer token or OAuth2.
$.components.securitySchemes
error
einstein-server-url-defined
API must define at least one server URL.
$
warn
einstein-content-type-json
JSON request bodies must use application/json.
$.paths[*][*].requestBody.content
error
einstein-no-trailing-slash
Paths must not have trailing slashes.
$.paths[*]~
warn
einstein-description-required
API info must include a description.
$.info

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:

  einstein-operation-id-required:
    description: All operations must have an operationId.
    message: "Operation is missing operationId."
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  einstein-summary-not-empty:
    description: All operations must have a summary.
    message: "Operation must have a non-empty summary."
    severity: error
    given: "$.paths[*][*]"
    then:
      field: summary
      function: truthy

  einstein-tags-required:
    description: All operations must have at least one tag.
    message: "Operation must have at least one tag."
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  einstein-response-200-required:
    description: All operations must define a 200 success response.
    message: "Operation must define a 200 success response."
    severity: error
    given: "$.paths[*][*].responses"
    then:
      function: schema
      functionOptions:
        schema:
          required: ["200"]

  einstein-auth-required:
    description: All Einstein APIs require bearer token or OAuth2.
    message: "API must declare bearer or OAuth2 security scheme."
    severity: error
    given: "$.components.securitySchemes"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["bearerAuth"]
            - required: ["oauth2"]

  einstein-server-url-defined:
    description: API must define at least one server URL.
    message: "API must define at least one server."
    severity: error
    given: "$"
    then:
      field: servers
      function: truthy

  einstein-content-type-json:
    description: JSON request bodies must use application/json.
    message: "JSON request body should declare application/json."
    severity: warn
    given: "$.paths[*][*].requestBody.content"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["application/json"]
            - required: ["multipart/form-data"]

  einstein-no-trailing-slash:
    description: Paths must not have trailing slashes.
    message: "Path must not end with a slash."
    severity: error
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  einstein-description-required:
    description: API info must include a description.
    message: "API info must include a description."
    severity: warn
    given: "$.info"
    then:
      field: description
      function: truthy