{
  "openapi": "3.0.3",
  "info": {
    "version": "0.0.1",
    "title": "Angular.Schule Book API",
    "description": "Simple HTTP backend for serving books"
  },
  "servers": [
    {
      "url": "https://api.angular.schule"
    }
  ],
  "tags": [
    {
      "name": "books",
      "description": "Books"
    },
    {
      "name": "booksslow",
      "description": "Books with slow response time"
    }
  ],
  "paths": {
    "/books": {
      "get": {
        "tags": [
          "books"
        ],
        "summary": "Get all books",
        "responses": {
          "200": {
            "description": "List of all books",
            "content": {
              "application/json": {
                "schema": {
                  "title": "Books",
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Book"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "books"
        ],
        "summary": "RESET store to initial state",
        "responses": {
          "200": {
            "description": "All data is now on initial state"
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "books"
        ],
        "summary": "Create a new book",
        "requestBody": {
          "description": "A new book to be stored",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Book"
              }
            }
          }
        },
        "x-codegen-request-body-name": "book",
        "responses": {
          "201": {
            "description": "Book was created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          },
          "400": {
            "description": "Invalid data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "409": {
            "description": "Book does already exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/slow": {
      "get": {
        "tags": [
          "booksslow"
        ],
        "summary": "Get all books, but with a 5s delay",
        "responses": {
          "200": {
            "description": "List of all books (slow!)",
            "content": {
              "application/json": {
                "schema": {
                  "title": "Books",
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Book"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/search/{searchTerm}": {
      "get": {
        "tags": [
          "books"
        ],
        "summary": "Get all books matching the given search term (case insensitive). The properties isbn, title, authors, published (interpreted as ISO string), subtitle and description are evaluated for a match.",
        "parameters": [
          {
            "name": "searchTerm",
            "in": "path",
            "description": "search term (treated case insensitive)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of all books matching the give search term",
            "content": {
              "application/json": {
                "schema": {
                  "title": "Books",
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Book"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/{isbn}/rate": {
      "post": {
        "tags": [
          "books"
        ],
        "summary": "Update rating of a book to a given value",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "The new rating value for the given book",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Rating"
              }
            }
          }
        },
        "x-codegen-request-body-name": "rating",
        "responses": {
          "200": {
            "description": "Rating has been updated"
          },
          "400": {
            "description": "Invalid data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "404": {
            "description": "Book does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/{isbn}": {
      "get": {
        "tags": [
          "books"
        ],
        "summary": "Get a single book by ISBN",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returns the book with the requested ISBN",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          },
          "404": {
            "description": "Book does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": [
          "books"
        ],
        "summary": "Update an existing book",
        "description": "Requires a full book entry, ISBN in query and body must match",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book to update",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "An existing book to update",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Book"
              }
            }
          }
        },
        "x-codegen-request-body-name": "book",
        "responses": {
          "200": {
            "description": "Book was updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          },
          "400": {
            "description": "Invalid data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "404": {
            "description": "Book does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "books"
        ],
        "summary": "Delete a book",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book to delete",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Book was deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "404": {
            "description": "Book does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/{isbn}/slow": {
      "get": {
        "tags": [
          "booksslow"
        ],
        "summary": "Get a single book by ISBN, but with a delay between 1 and 5 seconds, depending on the rating",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returns the book with the requested ISBN (slow!)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          },
          "404": {
            "description": "Book does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/books/{isbn}/check": {
      "get": {
        "tags": [
          "books"
        ],
        "summary": "Return whether ISBN exists or not",
        "parameters": [
          {
            "name": "isbn",
            "in": "path",
            "description": "ISBN of the book",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returns whether the ISBN exists in the database or not (boolean)"
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        }
      }
    },
    "/avatar/{num}": {
      "get": {
        "tags": [
          "avatar"
        ],
        "summary": "Get avatar image for number",
        "parameters": [
          {
            "name": "num",
            "in": "path",
            "description": "ID number of avatar",
            "required": true,
            "schema": {
              "type": "number"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Avatar with the given ID number",
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/secure/books": {
      "get": {
        "tags": [
          "books"
        ],
        "summary": "Get all books - SECURED via OAuth 2.0",
        "description": "Please authorize first!\nUser: auth@angular.schule\nPass: auth0123",
        "responses": {
          "200": {
            "description": "List of all books",
            "content": {
              "application/json": {
                "schema": {
                  "title": "Books",
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Book"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Unexpected Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestError"
                }
              }
            }
          }
        },
        "security": [
          {
            "Auth0": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "Auth0": {
        "type": "oauth2",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://angular-schule.eu.auth0.com/authorize",
            "scopes": {}
          }
        }
      }
    },
    "schemas": {
      "Book": {
        "type": "object",
        "properties": {
          "isbn": {
            "type": "string",
            "example": "9783864907791",
            "description": "ISBN, which is used as identifier - only numbers are allowed (no hyphens)"
          },
          "title": {
            "type": "string",
            "example": "Angular",
            "description": "Title of the book"
          },
          "authors": {
            "description": "List of all authors of the book",
            "example": [
              "Ferdinand Malcher",
              "Johannes Hoppe",
              "Danny Koppenhagen"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "subtitle": {
            "example": "Grundlagen, fortgeschrittene Themen und Best Practices",
            "description": "Subtitle of the book",
            "type": "string"
          },
          "rating": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "format": "int32",
            "example": 4,
            "description": "Rating of the book as stars, from one star (bad) to five stars (great)"
          },
          "published": {
            "format": "date-time",
            "example": "2020-10-12T00:00:00.000Z",
            "description": "date-time as defined by RFC3339 (http://www.ietf.org/rfc/rfc3339.txt) - like new Date().toISOString();",
            "type": "string"
          },
          "description": {
            "type": "string",
            "example": "Lernen Sie Angular mit diesem Praxisbuch! Mit einem anspruchsvollen Beispielprojekt führen wir Sie durch die Welt von Angular.",
            "description": "Short description of the book"
          },
          "thumbnails": {
            "description": "Images of the book, which are used as thumbnails",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Thumbnail"
            }
          },
          "price": {
            "example": 36.9,
            "description": "Price of the book",
            "type": "number",
            "minimum": 0
          },
          "firstThumbnailUrl": {
            "example": "https://api.angular.schule/images/cover/angular_auflage3.jpg",
            "description": "URL of the first thumbnail, just a shorthand",
            "readOnly": true,
            "type": "string"
          }
        },
        "required": [
          "isbn",
          "title",
          "rating",
          "description"
        ],
        "description": "The main entity of this API"
      },
      "Thumbnail": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "example": "https://api.angular.schule/images/cover/angular_auflage3.jpg",
            "description": "Image to display"
          },
          "title": {
            "type": "string",
            "example": "Front Cover",
            "description": "Caption of the image"
          }
        },
        "required": [
          "url",
          "title"
        ],
        "description": "Link to an image, which is used as a thumbnail"
      },
      "Rating": {
        "type": "object",
        "properties": {
          "rating": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "format": "int32",
            "example": 4,
            "description": "Rating value for a book from one star (bad) to five stars (great)"
          }
        },
        "required": [
          "rating"
        ],
        "description": "An object with a rating value (1...5)"
      },
      "RestError": {
        "type": "object",
        "properties": {
          "error": {
            "example": "error text",
            "description": "an explanation of the error",
            "type": "string"
          }
        },
        "description": "simple object describing the issue"
      },
      "DeleteResponse": {
        "type": "object",
        "properties": {
          "delete": {
            "example": true,
            "description": "deletion success state",
            "type": "boolean"
          }
        },
        "description": "object returned for delete operations"
      }
    }
  }
}