Walmart · API Governance Rules

Walmart API Rules

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

10 Rules error 4 warn 6
View Rules File View on GitHub

Rule Categories

walmart

Rules

error
walmart-operation-ids-required
All operations must have an operationId
$.paths[*][*]
warn
walmart-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][*].summary
error
walmart-operation-tags-required
All operations must have at least one tag
$.paths[*][*]
warn
walmart-required-headers-defined
Walmart APIs require WM_SEC.ACCESS_TOKEN, WM_QOS.CORRELATION_ID, and WM_SVC.NAME headers on all operations
$.paths[*][get,post,put,patch,delete].parameters
warn
walmart-servers-include-sandbox
Walmart APIs should define both production and sandbox server URLs
$.servers
error
walmart-info-description
Info object must have a description
$.info
error
walmart-response-success-defined
Operations must define a successful (2xx) response
$.paths[*][*].responses
warn
walmart-paths-versioned
All paths must be versioned with /v3/ prefix for marketplace APIs
$.paths
warn
walmart-json-content-type
Request bodies should use application/json content type
$.paths[*][post,put,patch].requestBody.content
warn
walmart-response-schema-reference
Successful responses should reference a schema component
$.paths[*][*].responses['200'].content['application/json']

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  walmart-operation-ids-required:
    description: All operations must have an operationId
    severity: error
    given: "$.paths[*][*]"
    then:
      field: operationId
      function: truthy

  walmart-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-Za-z0-9]+)*$"

  walmart-operation-tags-required:
    description: All operations must have at least one tag
    severity: error
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  walmart-required-headers-defined:
    description: >-
      Walmart APIs require WM_SEC.ACCESS_TOKEN, WM_QOS.CORRELATION_ID, and
      WM_SVC.NAME headers on all operations
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].parameters"
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          contains:
            type: object
            properties:
              name:
                enum:
                  - WM_SEC.ACCESS_TOKEN
                  - WM_QOS.CORRELATION_ID

  walmart-servers-include-sandbox:
    description: Walmart APIs should define both production and sandbox server URLs
    severity: warn
    given: "$.servers"
    then:
      function: length
      functionOptions:
        min: 2

  walmart-info-description:
    description: Info object must have a description
    severity: error
    given: "$.info"
    then:
      field: description
      function: truthy

  walmart-response-success-defined:
    description: Operations must define a successful (2xx) response
    severity: error
    given: "$.paths[*][*].responses"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          anyOf:
            - required: ["200"]
            - required: ["201"]
            - required: ["204"]

  walmart-paths-versioned:
    description: All paths must be versioned with /v3/ prefix for marketplace APIs
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^\\/v[0-9]+"

  walmart-json-content-type:
    description: Request bodies should use application/json content type
    severity: warn
    given: "$.paths[*][post,put,patch].requestBody.content"
    then:
      field: application/json
      function: truthy

  walmart-response-schema-reference:
    description: Successful responses should reference a schema component
    severity: warn
    given: "$.paths[*][*].responses['200'].content['application/json']"
    then:
      field: schema
      function: truthy