Vendure · API Governance Rules

Vendure API Rules

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

9 Rules error 2 warn 6 info 1
View Rules File View on GitHub

Rule Categories

vendure

Rules

warn
vendure-info-license-gpl
License must reference GPL-3.0 (Vendure Core license).
$.info.license
info
vendure-info-contact-docs
Contact URL should point to docs.vendure.io.
$.info.contact
error
vendure-graphql-endpoint-uses-post
GraphQL endpoints must only expose POST.
$.paths[?(@property == '/' || @property == '/shop-api' || @property == '/admin-api')]
warn
vendure-operation-summary-title-case
Operation summaries must use Title Case.
$.paths[*][*].summary
error
vendure-operation-has-operation-id
Every operation must have an operationId.
$.paths[*][*]
warn
vendure-channel-token-header-name
When a parameter selects a channel token, the header must be named `vendure-token`.
$..parameters[?(@.in == 'header' && @.description && @.description.match(/channel/i))]
warn
vendure-asset-server-route-prefix
Asset Server paths must live under `/assets` or `/assets/preview`.
$.paths
warn
vendure-error-response-shape
4xx responses should include a description.
$.paths[*][*].responses[?(@property.match(/^4\d\d$/))]
warn
vendure-tags-defined
Each operation should have at least one tag.
$.paths[*][*]

Spectral Ruleset

Raw ↑
extends: spectral:oas
documentationUrl: https://github.com/api-evangelist/vendure
description: >-
  Spectral ruleset for Vendure OpenAPI specs. Encodes the conventions used by
  the Shop API, Admin API, and Asset Server REST surface modelled in this
  repository.
rules:
  vendure-info-license-gpl:
    description: License must reference GPL-3.0 (Vendure Core license).
    severity: warn
    given: $.info.license
    then:
      field: name
      function: pattern
      functionOptions:
        match: '^GPL-3\.0$'

  vendure-info-contact-docs:
    description: Contact URL should point to docs.vendure.io.
    severity: info
    given: $.info.contact
    then:
      field: url
      function: pattern
      functionOptions:
        match: '^https?://docs\.vendure\.io'

  vendure-graphql-endpoint-uses-post:
    description: GraphQL endpoints must only expose POST.
    severity: error
    given: "$.paths[?(@property == '/' || @property == '/shop-api' || @property == '/admin-api')]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          not:
            anyOf:
              - required: [get]
              - required: [put]
              - required: [patch]
              - required: [delete]

  vendure-operation-summary-title-case:
    description: Operation summaries must use Title Case.
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: '^[A-Z][A-Za-z0-9]*(?:\s+(?:[A-Z][A-Za-z0-9]*|[A-Z]+|(?:A|An|And|As|At|But|By|For|In|Of|On|Or|The|To|Via|With)))*$'

  vendure-operation-has-operation-id:
    description: Every operation must have an operationId.
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  vendure-channel-token-header-name:
    description: When a parameter selects a channel token, the header must be named `vendure-token`.
    severity: warn
    given: "$..parameters[?(@.in == 'header' && @.description && @.description.match(/channel/i))]"
    then:
      field: name
      function: pattern
      functionOptions:
        match: '^vendure-token$'

  vendure-asset-server-route-prefix:
    description: Asset Server paths must live under `/assets` or `/assets/preview`.
    severity: warn
    given: "$.paths"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          patternProperties:
            '^/assets(?:/preview)?(?:/[A-Za-z0-9{}._-]+)+$': true
          additionalProperties: true

  vendure-error-response-shape:
    description: 4xx responses should include a description.
    severity: warn
    given: "$.paths[*][*].responses[?(@property.match(/^4\\d\\d$/))]"
    then:
      field: description
      function: truthy

  vendure-tags-defined:
    description: Each operation should have at least one tag.
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: schema
      functionOptions:
        schema:
          type: array
          minItems: 1