Alchemy · API Governance Rules

Alchemy API Rules

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

32 Rules error 13 warn 15 info 4
View Rules File View on GitHub

Rule Categories

examples http info no openapi operation parameter paths request response schema security servers tags

Rules

warn
info-title-pattern
API title must start with "Alchemy" to follow provider naming convention.
$.info.title
error
info-description-required
API info must have a description.
$.info
error
info-version-required
API info must declare a version.
$.info
warn
info-contact-required
API info should include contact information.
$.info
error
openapi-version-3
Specs must use OpenAPI 3.0.x.
$.openapi
error
servers-defined
At least one server must be defined.
$
error
servers-https-only
All server URLs must use HTTPS.
$.servers[*].url
warn
servers-description-required
Each server must have a description.
$.servers[*]
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths[*]~
error
paths-no-query-strings
Paths must not contain query strings.
$.paths[*]~
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-summary-title-case
Operation summaries must start with "Alchemy" and use Title Case.
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
Every operation must have a description.
$.paths[*][get,post,put,patch,delete,options,head]
error
operation-id-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-id-camel-case
operationId must use camelCase.
$.paths[*][get,post,put,patch,delete].operationId
warn
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete,options,head]
warn
tags-global-defined
Global tags array must be defined.
$
warn
tags-description-required
Each global tag should have a description.
$.tags[*]
warn
parameter-description-required
All parameters must have a description.
$.paths[*][get,post,put,patch,delete].parameters[*]
info
request-body-json
Request bodies should use application/json content type.
$.paths[*][post,put,patch].requestBody.content
info
request-body-description
Request bodies should have a description.
$.paths[*][post,put,patch].requestBody
error
response-success-required
Every operation must define at least one 2xx response.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
Every response must have a description.
$.paths[*][get,post,put,patch,delete].responses[*]
warn
response-401-for-secured
Operations with security should define a 401 response.
$.paths[*][get,post,put,patch,delete][?(@.security)]
warn
schema-description-on-top-level
Top-level component schemas should have a description.
$.components.schemas[*]
info
schema-type-defined
Schemas should define a type.
$.components.schemas[*]
error
security-schemes-defined
Security schemes must be defined in components.
$.components
warn
security-scheme-description
Security schemes should have a description.
$.components.securitySchemes[*]
error
http-get-no-body
GET operations must not have a request body.
$.paths[*].get
warn
http-delete-no-body
DELETE operations should not have a request body.
$.paths[*].delete
error
no-empty-descriptions
Descriptions must not be empty strings.
$..description
info
examples-encouraged
Operations should include request/response examples.
$.paths[*][post,get].responses[*].content[*]

Spectral Ruleset

Raw ↑
rules:
  # INFO / METADATA
  info-title-pattern:
    description: API title must start with "Alchemy" to follow provider naming convention.
    message: "Info title must start with 'Alchemy'. Found: {{value}}"
    severity: warn
    given: "$.info.title"
    then:
      function: pattern
      functionOptions:
        match: "^Alchemy "

  info-description-required:
    description: API info must have a description.
    severity: error
    given: "$.info"
    then:
      field: description
      function: truthy

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

  info-contact-required:
    description: API info should include contact information.
    severity: warn
    given: "$.info"
    then:
      field: contact
      function: truthy

  # OPENAPI VERSION
  openapi-version-3:
    description: Specs must use OpenAPI 3.0.x.
    message: "OpenAPI version must be 3.0.x. Found: {{value}}"
    severity: error
    given: "$.openapi"
    then:
      function: pattern
      functionOptions:
        match: "^3\\.0\\."

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

  servers-https-only:
    description: All server URLs must use HTTPS.
    message: "Server URL must use HTTPS. Found: {{value}}"
    severity: error
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: "^https://"

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

  # PATHS — NAMING CONVENTIONS
  paths-no-trailing-slash:
    description: Paths must not end with a trailing slash.
    message: "Path must not end with a trailing slash. Found: {{path}}"
    severity: warn
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  paths-no-query-strings:
    description: Paths must not contain query strings.
    severity: error
    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,options,head]"
    then:
      field: summary
      function: truthy

  operation-summary-title-case:
    description: Operation summaries must start with "Alchemy" and use Title Case.
    message: "Summary should start with 'Alchemy'. Found: {{value}}"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^Alchemy "

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

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

  operation-id-camel-case:
    description: operationId must use camelCase.
    message: "operationId must be camelCase. Found: {{value}}"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

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

  # TAGS
  tags-global-defined:
    description: Global tags array must 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: "$.paths[*][get,post,put,patch,delete].parameters[*]"
    then:
      field: description
      function: truthy

  # REQUEST BODIES
  request-body-json:
    description: Request bodies should use application/json content type.
    severity: info
    given: "$.paths[*][post,put,patch].requestBody.content"
    then:
      function: truthy

  request-body-description:
    description: Request bodies should have a description.
    severity: info
    given: "$.paths[*][post,put,patch].requestBody"
    then:
      field: description
      function: defined

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

  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

  response-401-for-secured:
    description: Operations with security should define a 401 response.
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete][?(@.security)]"
    then:
      field: responses
      function: defined

  # SCHEMAS — PROPERTY NAMING
  schema-description-on-top-level:
    description: Top-level component schemas should have a description.
    severity: warn
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy

  schema-type-defined:
    description: Schemas should define a type.
    severity: info
    given: "$.components.schemas[*]"
    then:
      field: type
      function: defined

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

  security-scheme-description:
    description: Security schemes should have a description.
    severity: warn
    given: "$.components.securitySchemes[*]"
    then:
      field: description
      function: truthy

  # HTTP METHOD CONVENTIONS
  http-get-no-body:
    description: GET operations must not have a request body.
    severity: error
    given: "$.paths[*].get"
    then:
      field: requestBody
      function: falsy

  http-delete-no-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.
    message: "Description must not be an empty string."
    severity: error
    given: "$..description"
    then:
      function: truthy

  examples-encouraged:
    description: Operations should include request/response examples.
    severity: info
    given: "$.paths[*][post,get].responses[*].content[*]"
    then:
      field: examples
      function: defined