openapi: 3.0.3
info:
  title: Orders API
  version: 1.4.0
  description: Create, list and track customer orders for the storefront.
servers:
  - url: https://api.example.com/v1
    description: Production
tags:
  - name: Orders
    description: Everything about customer orders
paths:
  /orders:
    get:
      tags: [Orders]
      summary: List orders
      operationId: listOrders
      parameters:
        - name: status
          in: query
          description: Only return orders in this status
          schema:
            type: string
            enum: [open, shipped, cancelled]
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: A page of orders
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Order'
    post:
      tags: [Orders]
      summary: Create an order
      operationId: createOrder
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewOrder'
      responses:
        '201':
          description: Order created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '422':
          description: Validation failed
  /orders/{orderId}:
    parameters:
      - name: orderId
        in: path
        required: true
        schema:
          type: string
    get:
      tags: [Orders]
      summary: Get an order
      operationId: getOrder
      responses:
        '200':
          description: The order
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '404':
          description: Order not found
    delete:
      tags: [Orders]
      summary: Cancel an order
      operationId: cancelOrder
      responses:
        '204':
          description: Order cancelled
components:
  schemas:
    LineItem:
      type: object
      required: [sku, quantity]
      properties:
        sku:
          type: string
          example: MUG-001
        quantity:
          type: integer
          minimum: 1
    NewOrder:
      type: object
      required: [customerId, items]
      properties:
        customerId:
          type: string
        items:
          type: array
          items:
            $ref: '#/components/schemas/LineItem'
    Order:
      allOf:
        - $ref: '#/components/schemas/NewOrder'
        - type: object
          properties:
            id:
              type: string
            status:
              type: string
              enum: [open, shipped, cancelled]
            createdAt:
              type: string
              format: date-time
