openapi: "3.0.0" info: version: "1.1" title: AlgaStock description: "This is the API spect used during the \"Ignição React\" course" contact: name: Daniel Bonifacio email: daniel.bonifacio@algaworks.com servers: - url: https://localhost:3024 description: Local server paths: /products: get: summary: "Get all products" description: "Get all products stored and they relative id, price, available stock and a bunch of metadata." operationId: getAllProducts tags: - products responses: 200: description: Sunrise and sunset times response content: application/json: schema: type: array items: $ref: '#/components/schemas/Product' post: summary: "Insert a new product" description: "Insert a new product on the store" operationId: addProduct security: - BearerAuth: [admin] tags: - products requestBody: required: true content: application/json: schema: type: object properties: name: type: string example: Cookie price: type: number minimum: 0 format: float example: 1.5 stock: type: number minimum: 0 format: integer example: 25 responses: 201: description: Product sucessfully created 401: description: You don't have permission to create products 403: $ref: '#/components/responses/UnauthorizedError' /products/{productId}: get: summary: "Get single product" description: "Get a single product and they relative id, price, available stock and a bunch of metadata." operationId: getSingleProduct tags: - products parameters: - name: productId in: path description: "Id of the single product that you want to retrieve information." required: true schema: type: string example: "CTcswP9kijnxwFp6" responses: 200: description: Single product response content: application/json: schema: $ref: "#/components/schemas/Product" 404: description: Product not found delete: summary: "Delete single product" description: "Deletes a product and all him information" operationId: deleteSingleProduct security: - BearerAuth: [admin] tags: - products parameters: - name: productId in: path description: "ID of the single product that you want to delete." required: true schema: type: string example: "CTcswP9kijnxwFp6" responses: 200: description: Product sucessfully deleted 401: description: You don't have permission to delete this product 403: $ref: '#/components/responses/UnauthorizedError' patch: summary: "Update product fields" description: "Update specific product fields that" operationId: updateProduct security: - BearerAuth: [admin] tags: - products parameters: - name: productId in: path description: "ID of the single product that you want to update." required: true schema: type: string example: "CTcswP9kijnxwFp6" requestBody: description: '**Note:** You can provide only the fields that you want to update, like: `{ price: 1.75 }`' content: application/json: schema: type: object properties: name: type: string example: Cookie price: type: number minimum: 0 format: float example: 1.75 stock: type: number minimum: 0 format: integer example: 35 responses: 200: description: Product sucessfully updated 401: description: You don't have permission to update products 403: $ref: '#/components/responses/UnauthorizedError' /buy/{productId}: get: summary: "Buy one product" description: "Buy a product if it has available stock" operationId: buyOneProduct parameters: - name: productId in: path description: The ID of the product that you want to buy required: true schema: type: string example: "CTcswP9kijnxwFp6" security: - BearerAuth: [customer] tags: - products responses: 200: description: Product successfully bought 404: description: Product not found 401: description: 'Product has no more stock' content: application/json: schema: type: object properties: message: type: string example: 'Product has no more stock' 403: $ref: '#/components/responses/UnauthorizedError' /authentication/login: post: description: "SignIn User" operationId: signInUser tags: - authentication requestBody: required: true content: application/json: schema: type: object properties: user: type: string example: daniel pass: type: string example: s3curepassword123 responses: 200: description: Successful login content: application/json: schema: type: object properties: _id: type: string description: 'The logged in user ID' example: 'mvpht5Ylt3GaGIeE' user: type: string description: 'The logged in user name' example: 'danielbonifacio' email: type: string description: 'The logged in user email' example: 'daniel.bonifacio@algaworks.com' role: type: string description: 'User role (admin or customer)' example: 'customer' token: type: string description: 'The logged in user unique token' example: 'Ge6HkvYS9dtypYl6?Ge6HkvYS9dtypYl6?Ge6HkvYS9dtypYl6' createdAt: type: string example: '2020-08-04T12:45:28.612Z' updatedAt: type: string example: '2020-08-04T12:45:28.612Z' 401: description: Wrong credentials content: application/json: schema: type: object properties: message: type: string example: "We could not log you in" components: securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT responses: UnauthorizedError: description: Access token is missing or invalid schemas: Product: type: object properties: _id: type: string description: 'The product ID' example: "CTcswP9kijnxwFp6" name: type: string description: 'The product name' example: "Cookie" price: type: number description: 'The product price' example: 1.5 stock: type: string description: "The available stock of the product" example: 25 tags: - name: products description: Everything about products - name: authentication description: User access