{"openapi":"3.1.0","info":{"title":"Cedar Books practice API","version":"2.4.0","description":"The API of Cedar Books, the practice shop of QAIA Academy. Some answers are wrong on purpose: finding them is the exercise. Every visitor works in a private copy of the data that ends after 2 hours."},"servers":[{"url":"https://practice.qaia.io"}],"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer","description":"The token from POST /api/auth/login."}},"schemas":{"Error":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"Book":{"type":"object","required":["id","isbn","title","author","category","price","stock","published"],"properties":{"id":{"type":"integer"},"isbn":{"type":"string","pattern":"^\\d{13}$"},"title":{"type":"string"},"author":{"type":"string"},"category":{"type":"string","enum":["fiction","science","children","history","offers"]},"price":{"type":"number","description":"Two decimals, no currency sign."},"was":{"type":"number"},"stock":{"type":"integer","minimum":0},"published":{"type":"string","format":"date"}}},"BookDetail":{"allOf":[{"$ref":"#/components/schemas/Book"},{"type":"object","properties":{"blurb":{"type":"string"},"related":{"type":"array","items":{"type":"integer"}},"reviews":{"type":"array","items":{"$ref":"#/components/schemas/Review"}}}}]},"Review":{"type":"object","properties":{"id":{"type":"integer"},"bookId":{"type":"integer"},"rating":{"type":"integer","minimum":1,"maximum":5},"comment":{"type":"string","maxLength":500}}},"BasketLine":{"type":"object","properties":{"id":{"type":"string"},"bookId":{"type":"integer"},"title":{"type":"string"},"price":{"type":"number"},"qty":{"type":"integer","minimum":1,"maximum":10}}},"Basket":{"type":"object","properties":{"lines":{"type":"array","items":{"$ref":"#/components/schemas/BasketLine"}},"coupons":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string"},"amount":{"type":"number"}}}},"totals":{"type":"object","properties":{"subtotal":{"type":"number"},"discount":{"type":"number"},"total":{"type":"number"},"delivery":{"type":"number"},"toPay":{"type":"number"}}}}},"Address":{"type":"object","required":["name","line1","city","postcode"],"properties":{"name":{"type":"string"},"line1":{"type":"string"},"city":{"type":"string"},"postcode":{"type":"string"}}},"Order":{"type":"object","properties":{"id":{"type":"integer"},"account":{"type":"string"},"status":{"type":"string","enum":["confirmed"]},"placedAt":{"type":"string","format":"date-time"},"lines":{"type":"array","items":{"$ref":"#/components/schemas/BasketLine"}},"subtotal":{"type":"number"},"discount":{"type":"number"},"total":{"type":"number"},"delivery":{"type":"number"},"toPay":{"type":"number"},"coupon":{"type":["string","null"]},"address":{"$ref":"#/components/schemas/Address"}}}}},"paths":{"/api/auth/login":{"post":{"summary":"Sign in a demo shopper","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"Signed in","content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string"},"account":{"type":"object"}}}}}},"401":{"description":"Email or password is wrong (the same message for both)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"423":{"description":"Locked for 15 minutes after 5 failed sign-ins","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/auth/logout":{"post":{"summary":"Sign out","responses":{"204":{"description":"Signed out"}}}},"/api/books":{"get":{"summary":"Search the catalogue","parameters":[{"name":"q","in":"query","schema":{"type":"string"},"description":"Words of the title or author, or an ISBN. Accents are ignored."},{"name":"author","in":"query","schema":{"type":"string"}},{"name":"category","in":"query","schema":{"type":"string"}},{"name":"sort","in":"query","schema":{"type":"string","enum":["relevance","price-asc","price-desc","newest"],"default":"relevance"}},{"name":"page","in":"query","schema":{"type":"integer","minimum":1,"default":1}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":50,"default":12}}],"responses":{"200":{"description":"A page of books","content":{"application/json":{"schema":{"type":"object","properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/Book"}},"page":{"type":"integer"},"pages":{"type":"integer"},"total":{"type":"integer"},"pageNumbers":{"type":"array","items":{"type":"integer"}}}}}}},"400":{"description":"A query value is out of range","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/books/{id}":{"get":{"summary":"One book","parameters":[{"name":"id","in":"path","required":true,"description":"The book id","schema":{"type":"string"}}],"responses":{"200":{"description":"The book","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BookDetail"}}}},"404":{"description":"No such book","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/books/{id}/reviews":{"post":{"summary":"Review a book","security":[{"bearer":[]}],"parameters":[{"name":"id","in":"path","required":true,"description":"The book id","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["rating"],"properties":{"rating":{"type":"integer","minimum":1,"maximum":5},"comment":{"type":"string","maxLength":500}}}}}},"responses":{"201":{"description":"Saved","content":{"application/json":{"schema":{"type":"object","properties":{"review":{"$ref":"#/components/schemas/Review"}}}}}},"401":{"description":"Sign in first","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such book","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Rating or comment out of range","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/basket":{"get":{"summary":"Your basket","responses":{"200":{"description":"The basket","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}}}}},"/api/basket/items":{"post":{"summary":"Add a book","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["bookId"],"properties":{"bookId":{"type":"integer"},"qty":{"type":"integer","minimum":1,"maximum":10,"default":1}}}}}},"responses":{"200":{"description":"Added to its line","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}},"201":{"description":"A new line","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}},"404":{"description":"No such book","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"Out of stock","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Quantity out of range or above the stock","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/basket/items/{lineId}":{"patch":{"summary":"Change a quantity","parameters":[{"name":"lineId","in":"path","required":true,"description":"The basket line, for example L1","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["qty"],"properties":{"qty":{"type":"integer","minimum":1,"maximum":10}}}}}},"responses":{"200":{"description":"Changed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}},"404":{"description":"No such line","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Quantity out of range or above the stock","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"delete":{"summary":"Remove a line","parameters":[{"name":"lineId","in":"path","required":true,"description":"The basket line","schema":{"type":"string"}}],"responses":{"200":{"description":"Removed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}},"404":{"description":"No such line","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/coupons/apply":{"post":{"summary":"Apply one coupon code (a second code replaces the first)","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["code"],"properties":{"code":{"type":"string"}}}}}},"responses":{"200":{"description":"Applied","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Basket"}}}},"400":{"description":"Malformed code","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Unknown code","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Expired, used up, or not allowed for this basket","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/checkout":{"post":{"summary":"Pay with a test card","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["card","address"],"properties":{"card":{"type":"string","description":"4242 4242 4242 4242 approved, 4000 0000 0000 0002 declined, 4000 0000 0000 0119 slow bank"},"address":{"$ref":"#/components/schemas/Address"}}}}}},"responses":{"201":{"description":"Order confirmed","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"},"order":{"$ref":"#/components/schemas/Order"}}}}}},"402":{"description":"Card declined: no order is made","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"The basket is empty","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Not a test card, or the address is missing","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"504":{"description":"The bank did not answer within 10 seconds","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/orders":{"get":{"summary":"Your orders","security":[{"bearer":[]}],"responses":{"200":{"description":"Your orders","content":{"application/json":{"schema":{"type":"object","properties":{"orders":{"type":"array","items":{"$ref":"#/components/schemas/Order"}}}}}}},"401":{"description":"Sign in first","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/orders/{id}":{"get":{"summary":"One of your orders","security":[{"bearer":[]}],"parameters":[{"name":"id","in":"path","required":true,"description":"The order number","schema":{"type":"string"}}],"responses":{"200":{"description":"The order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}},"401":{"description":"Sign in first","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such order among yours","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/mailbox":{"get":{"summary":"The confirmation messages of this practice session (nothing is ever emailed)","responses":{"200":{"description":"Messages","content":{"application/json":{"schema":{"type":"object","properties":{"messages":{"type":"array","items":{"type":"object"}}}}}}}}}},"/api/openapi.json":{"get":{"summary":"This document","responses":{"200":{"description":"OpenAPI 3.1","content":{"application/json":{"schema":{"type":"object"}}}}}}}}}