{
  "openapi": "3.0.3",
  "info": {
    "title": "API Shield Demo API",
    "version": "1.0.0",
    "description": "A small Cloudflare Worker API designed to exercise API Shield schema validation, endpoint management, and logging."
  },
  "servers": [
    {
      "url": "https://api-shield-demo.example.com",
      "description": "Replace with your deployed hostname before uploading to API Shield."
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Check service health",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Healthy service",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "summary": "Get the schema used by this demo",
        "operationId": "getOpenApi",
        "responses": {
          "200": {
            "description": "OpenAPI schema",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/catalog": {
      "get": {
        "summary": "List catalog items",
        "operationId": "listCatalog",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "electronics",
                "office",
                "grocery",
                "home"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Catalog items",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query"
          }
        }
      }
    },
    "/v1/customers/{customerId}": {
      "get": {
        "summary": "Get a customer profile",
        "operationId": "getCustomer",
        "parameters": [
          {
            "name": "customerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^cus_[0-9]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "404": {
            "description": "Customer not found"
          }
        }
      }
    },
    "/v1/orders": {
      "get": {
        "summary": "List orders",
        "operationId": "listOrders",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "created",
                "paid",
                "shipped",
                "cancelled"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderListResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an order",
        "operationId": "createOrder",
        "parameters": [
          {
            "name": "X-Demo-Client",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "404": {
            "description": "Unknown SKU"
          }
        }
      }
    },
    "/v1/orders/{orderId}": {
      "get": {
        "summary": "Get an order by id",
        "operationId": "getOrder",
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^ord_[a-zA-Z0-9]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "404": {
            "description": "Order not found"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ok",
          "service",
          "now"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "service": {
            "type": "string"
          },
          "now": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CatalogResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "items",
          "total",
          "limit",
          "category"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CatalogItem"
            }
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "category": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "CatalogItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sku",
          "name",
          "category",
          "priceCents"
        ],
        "properties": {
          "sku": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "priceCents": {
            "type": "integer"
          }
        }
      },
      "Customer": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "email",
          "tier"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "tier": {
            "type": "string",
            "enum": [
              "gold",
              "silver",
              "bronze"
            ]
          }
        }
      },
      "OrderItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sku",
          "name",
          "quantity",
          "unitPriceCents",
          "lineTotalCents"
        ],
        "properties": {
          "sku": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1
          },
          "unitPriceCents": {
            "type": "integer",
            "minimum": 0
          },
          "lineTotalCents": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "Order": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "customerId",
          "status",
          "lineItems",
          "totalCents",
          "createdAt",
          "note"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "customerId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "paid",
              "shipped",
              "cancelled"
            ]
          },
          "lineItems": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderItem"
            }
          },
          "totalCents": {
            "type": "integer",
            "minimum": 0
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "note": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "OrderListResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "items",
          "total",
          "limit",
          "status"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Order"
            }
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "OrderCreateRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "customerId",
          "items"
        ],
        "properties": {
          "customerId": {
            "type": "string",
            "pattern": "^cus_[0-9]+$"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "sku",
                "quantity"
              ],
              "properties": {
                "sku": {
                  "type": "string",
                  "pattern": "^sku_[a-z0-9_]+$"
                },
                "quantity": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "note": {
            "type": "string",
            "maxLength": 280
          }
        }
      }
    }
  }
}