diff --git a/.github/workflows/validate-openapi.yml b/.github/workflows/validate-openapi.yml new file mode 100644 index 0000000..852074c --- /dev/null +++ b/.github/workflows/validate-openapi.yml @@ -0,0 +1,23 @@ +name: Validate OpenAPI Spec + +on: + push: + paths: + - "openapi.yml" + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm ci + + - name: Validate OpenAPI spec + run: npm run lint:openapi diff --git a/docs/index.html b/docs/index.html index 088fe4d..366f70c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,756 +1,24 @@ +
+Download OpenAPI specification:Download
HTTP API reference documentation for the Fauna JavaScript sample -app.
-The app uses Fauna and Node.js to create HTTP API endpoints for a sample -e-commerce store. You can use the endpoints to manage customers, -products, and orders for the store.
-For an overview and more details, see the -README.
-Requests to the endpoints require no authentication. Internally, requests to
-Fauna are authenticated using a Fauna key's secret. You pass the secret
-using the FAUNA_SECRET
environment variable in .env
.
For setup instructions, see the -README.
-Create a customer with the specified details.
-name required | string Customer name - |
email required | string <email> Customer's email address. Must be unique. -Internally, the |
required | object Customer's mailing address. - |
{- "name": "John Doe",
- "email": "john.doe@example.com",
- "address": {
- "street": "123 Main St",
- "city": "San Francisco",
- "state": "CA",
- "postalCode": "12345",
- "country": "United States"
}
}
{- "id": "111",
- "name": "John Doe",
- "email": "john.doe@example.com",
- "address": {
- "street": "123 Main St",
- "city": "San Francisco",
- "state": "CA",
- "postalCode": "12345",
- "country": "United States"
}
}
Fetch the details of a customer by their ID.
-id required | string ID of the customer to retrieve. - |
curl -v http://localhost:8000/customers/111
{- "id": "111",
- "name": "John Doe",
- "email": "john.doe@example.com",
- "address": {
- "street": "123 Main St",
- "city": "San Francisco",
- "state": "CA",
- "postalCode": "12345",
- "country": "United States"
}
}
Update the details of a customer by their ID.
-id required | string ID of the customer to update. - |
name required | string Customer name - |
email required | string <email> Customer's email address. Must be unique. -Internally, the |
required | object Customer's mailing address. - |
{- "name": "John Doe",
- "email": "john.doe@example.com",
- "address": {
- "street": "123 Main St",
- "city": "San Francisco",
- "state": "CA",
- "postalCode": "12345",
- "country": "United States"
}
}
{- "id": "111",
- "name": "John Doe",
- "email": "john.doe@example.com",
- "address": {
- "street": "123 Main St",
- "city": "San Francisco",
- "state": "CA",
- "postalCode": "12345",
- "country": "United States"
}
}
category | string Category name to filter products by. - |
nextToken | string Accepts a pagination token. The endpoint's responses
-return these tokens in the |
pageSize | integer Default: 10 Number of products to return per page. - |
curl -v 'http://localhost:8000/products?category=books&pageSize=1'
{- "results": [
- {
- "id": "123",
- "name": "The Old Man and the Sea",
- "price": 899,
- "description": "A book by Ernest Hemingway",
- "stock": 10,
- "category": {
- "id": "123",
- "name": "books",
- "description": "Bargain books!"
}
}
], - "nextToken": "hdW..."
}
Create a product with the specified details.
-name required | string Name of the product. Must be unique. -Internally, the |
description required | string Description of the product. - |
price required | number Price of the product in USD cents. -Internally, the |
stock required | integer Quantity of the product available in stock. -Internally, the |
category required | string Name of the product's category. Must match an existing category. -Internally, this field contains a reference to a |
{- "name": "The Old Man and the Sea",
- "price": 899,
- "description": "A book by Ernest Hemingway",
- "stock": 10,
- "category": "books"
}
{- "id": "123",
- "name": "The Old Man and the Sea",
- "price": 899,
- "description": "A book by Ernest Hemingway",
- "stock": 10,
- "category": {
- "id": "123",
- "name": "books",
- "description": "Bargain books!"
}
}
Update the details of a product by its ID.
-id required | string ID of the product to update. - |
name required | string Name of the product. Must be unique. -Internally, the |
description required | string Description of the product. - |
price required | number Price of the product in USD cents. -Internally, the |
stock required | integer Quantity of the product available in stock. -Internally, the |
category required | string Name of the product's category. Must match an existing category. -Internally, this field contains a reference to a |
{- "name": "The Old Man and the Sea",
- "price": 899,
- "description": "A book by Ernest Hemingway",
- "stock": 10,
- "category": "books"
}
{- "id": "123",
- "name": "The Old Man and the Sea",
- "price": 899,
- "description": "A book by Ernest Hemingway",
- "stock": 10,
- "category": {
- "id": "123",
- "name": "books",
- "description": "Bargain books!"
}
}
minPrice | number Minimum price to filter products by. - |
maxPrice | number Maximum price to filter products by. - |
nextToken | string Accepts a pagination token. The endpoint's responses
-return these tokens in the |
pageSize | integer Default: 10 Number of products to return per page. - |
curl -v 'http://localhost:8000/products/by-price?minPrice=199&maxPrice=1099&pageSize=1'
{- "results": [
- {
- "id": "123",
- "name": "The Old Man and the Sea",
- "description": "A book by Ernest Hemingway",
- "price": 899,
- "stock": 10,
- "category": {
- "id": "123",
- "name": "books",
- "description": "Bargain books!"
}
}
], - "nextToken": "hdW..."
}
Get, create, and update customer orders for the e-commerce store.
-You can also use these endpoints to create and udpate a customer's cart.
-A customer's cart is an order with the cart
status. A customer can have
-one cart at a time.
An order contains zero or more items. An item links a product, with a -quantity, to an order.
-Get the details of a customer's cart order.
-id required | string ID of the customer. - |
curl -v http://localhost:8000/customers/111/cart
{- "id": "123",
- "items": {
- "after": "hdW..."
}, - "total": 0,
- "status": "cart",
- "customer": {
- "id": "456"
}, - "createdAt": {
- "isoString": "2099-08-09T16:43:07.153186Z"
}, - "payment": { }
}
Get the details of a customer's cart. If no cart exists, create one with -no items.
-A customer's cart is an order with the cart
status. A customer can
-have one cart at a time.
To add items to a customer's cart, use the POST /customers/{id}/cart/item
endpoint.
Internally, the endpoint uses the getOrCreateCart()
user-defined
-function (UDF) to conditionally get or create the customer's cart.
id required | string ID of the customer. - |
curl -v -X POST http://localhost:8000/customers/111/cart
{- "id": "123",
- "items": {
- "after": "hdW..."
}, - "total": 0,
- "status": "cart",
- "customer": {
- "id": "456"
}, - "createdAt": {
- "isoString": "2099-08-09T16:43:07.153186Z"
}, - "payment": { }
}
Add an item to a customer's cart. If the order already contains the -item's product, update the item's quantity.
-If the customer has no cart, the request create ones.
-The request returns an item. An item links a product, with a quantity, -to an order. An order contains zero or more items.
-Internally, the endpoint uses the createOrUpdateCartItem()
-user-defined function (UDF) to conditionally update the item's quantity
-and create a new cart. The UDF also handles various validations and
-error cases for the request.
id required | string ID of the customer. - |
productName required | string Name of an existing product to add to the order. - |
quantity required | integer Quantity of the product to add to the order. -Must be a non-negative integer. The quantity must be less than the product's Internally, the |
{- "productName": "The Old Man and the Sea",
- "quantity": 1
}
{- "id": 123,
- "order": {
- "id": 456
}, - "product": {
- "id": 789
}, - "quantity": 1
}
Get the details of an order by its ID.
-id required | string ID of the order to fetch. - |
curl -v http://localhost:8000/orders/123
{- "id": "123",
- "items": {
- "after": "hdW..."
}, - "total": 0,
- "status": "cart",
- "customer": {
- "id": "456"
}, - "createdAt": {
- "isoString": "2099-08-09T16:43:07.153186Z"
}, - "payment": { }
}
Update the details of an order by its ID.
-Changing the order's status
to processing
runs a checkout on the order.
Internally, the endpoint uses the checkout()
user-defined function
-(UDF) to validate orders during checkout. The UDF:
processing
status.payment
.id required | string ID of the order to update. - |
status | string Enum: "cart" "processing" "shipped" "delivered" Status of the order. -An order's status can only transition as follows: -
Internally, the endpoint uses the |
payment | object Default: {} Arbitrary object containing payment information. -You can only update payment information if the |
{- "status": "processing"
}
{- "id": "123",
- "items": {
- "after": "hdW..."
}, - "total": 0,
- "status": "cart",
- "customer": {
- "id": "456"
}, - "createdAt": {
- "isoString": "2099-08-09T16:43:07.153186Z"
}, - "payment": { }
}
Get the details of a customer's orders using the customer's ID.
-id required | string ID of the customer. - |
nextToken | string Accepts a pagination token. The endpoint's responses
-return these tokens in the |
pageSize | integer Default: 10 Number of products to return per page. - |
curl -v 'http://localhost:8000/customers/111/orders?pageSize=1'
{- "results": [
- {
- "id": "123",
- "payment": { },
- "createdAt": "2024-08-09T21:06:29.209471Z",
- "status": "cart",
- "total": 53.92,
- "items": {
- "data": [
- {
- "coll": {
- "name": "OrderItem"
}, - "id": "456",
- "ts": {
- "isoString": "2024-08-09T21:06:29.422Z"
}, - "order": {
- "coll": {
- "name": "Order"
}, - "id": "123"
}, - "product": {
- "coll": {
- "name": "Product"
}, - "id": "789"
}, - "quantity": 2
}, - {
- "coll": {
- "name": "OrderItem"
}, - "id": "012",
- "ts": {
- "isoString": "2024-08-09T21:06:29.422Z"
}, - "order": {
- "coll": {
- "name": "Order"
}, - "id": "123"
}, - "product": {
- "coll": {
- "name": "Product"
}, - "id": "345"
}, - "quantity": 1
}, - {
- "coll": {
- "name": "OrderItem"
}, - "id": "678",
- "ts": {
- "isoString": "2024-08-09T21:06:29.422Z"
}, - "order": {
- "coll": {
- "name": "Order"
}, - "id": "123"
}, - "product": {
- "coll": {
- "name": "Product"
}, - "id": "901"
}, - "quantity": 3
}
]
}, - "customer": {
- "id": "111",
- "name": "John Doe",
- "email": "john.doe@example.com"
}
}
], - "nextToken": "hdW..."
}