From fce9a3a25da405adebe810d8b36b703a3dff61b1 Mon Sep 17 00:00:00 2001 From: ISHIMWE Ami Paradis <141851169+amiparadis250@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:04:05 +0200 Subject: [PATCH] Image uploading, Authorization process fixed Swagger already working --- package-lock.json | 18 ++ package.json | 2 + src/swagger.json | 524 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 383 insertions(+), 161 deletions(-) diff --git a/package-lock.json b/package-lock.json index b54d919..5c0816c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,8 @@ "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/node": "^20.11.17", + "@types/swagger-jsdoc": "^6.0.4", + "@types/swagger-ui-express": "^4.1.6", "babel-jest": "^29.7.0", "coveralls": "^3.1.1", "coveralls-next": "^4.2.0", @@ -3054,6 +3056,22 @@ "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "dev": true }, + "node_modules/@types/swagger-jsdoc": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/@types/swagger-jsdoc/-/swagger-jsdoc-6.0.4.tgz", + "integrity": "sha512-W+Xw5epcOZrF/AooUM/PccNMSAFOKWZA5dasNyMujTwsBkU74njSJBpvCCJhHAJ95XRMzQrrW844Btu0uoetwQ==", + "dev": true + }, + "node_modules/@types/swagger-ui-express": { + "version": "4.1.6", + "resolved": "https://registry.npmjs.org/@types/swagger-ui-express/-/swagger-ui-express-4.1.6.tgz", + "integrity": "sha512-UVSiGYXa5IzdJJG3hrc86e8KdZWLYxyEsVoUI4iPXc7CO4VZ3AfNP8d/8+hrDRIqz+HAaSMtZSqAsF3Nq2X/Dg==", + "dev": true, + "dependencies": { + "@types/express": "*", + "@types/serve-static": "*" + } + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", diff --git a/package.json b/package.json index d683c0f..111e337 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,8 @@ "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/node": "^20.11.17", + "@types/swagger-jsdoc": "^6.0.4", + "@types/swagger-ui-express": "^4.1.6", "babel-jest": "^29.7.0", "coveralls": "^3.1.1", "coveralls-next": "^4.2.0", diff --git a/src/swagger.json b/src/swagger.json index 7e27ddd..03dd27f 100644 --- a/src/swagger.json +++ b/src/swagger.json @@ -56,8 +56,22 @@ "scheme": "bearer", "bearerFormat": "JWT" } + }, + "schemas": { + "MulterFile": { + "type": "object", + "properties": { + "fieldname": { "type": "string" }, + "originalname": { "type": "string" }, + "encoding": { "type": "string" }, + "mimetype": { "type": "string" }, + "buffer": { "type": "string" }, + "size": { "type": "integer" } + } + } } }, + "security": [ { "bearerAuth": [] @@ -183,7 +197,7 @@ } } }, - "409": { + "500": { "description": "Wrong login credentials" } } @@ -194,11 +208,7 @@ "summary": "Get all users for the admin panel", "tags": ["Users", "Authentication"], "parameters": [ - { - "name": "token", - "in": "header", - "type": "string" - } + ], "responses": { "200": { @@ -216,9 +226,7 @@ "tags": ["Users", "Authentication"], "parameters": [ { - "name": "token", - "in": "header", - "required": true, + "schema": { "type": "string" } @@ -265,151 +273,353 @@ } } }, - "/api/blogs": { - "post": { - "summary": "Create a blog with valid details", - "tags": ["Blogs"], - "consumes": ["multipart/form-data"], - "parameters": [ - { - "name": "Authorization", - "in": "header", - "type": "string" - }, - { - "name": "title", - "in": "formData", - "type": "string", - "required": true - }, - { - "name": "image", - "in": "formData", - "type": "file", - "required": true - }, - { - "name": "content", - "in": "formData", - "type": "string", - "required": true - }, - { - "name": "description", - "in": "formData", - "type": "string", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "get": { - "summary": "Read blogs", - "tags": ["Blogs"], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/api/blogs/{id}": { - "get": { - "summary": "Read single blogs", - "tags": ["Blogs"], - "parameters": [ - { - "name": "id", - "in": "path", - "type": "string", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "put": { - "summary": "Update a blog", - "tags": ["Blogs"], - "consumes": ["multipart/form-data"], - "parameters": [ - { - "name": "token", - "in": "header", - "type": "string", - "required": true - }, - { - "name": "id", - "in": "path", - "type": "string", - "required": true - }, - { - "name": "title", - "in": "formData", - "type": "string", - "required": true - }, - { - "name": "image", - "in": "formData", - "type": "file", - "required": true + + + "/api/blogs": { + "post": { + "summary": "Create a blog with valid details", + "tags": ["Blogs"], + "requestBody": { + "required": true, + "content": { + "multipart/form-data": { + "schema": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "file": { "type": "string", "format": "binary" + } + } + } + } + } + }, + "parameters": [ + { + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "data": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "imgsrc": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "user": { "type": "string" } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + } + } }, - { - "name": "content", - "in": "formData", - "type": "string", - "required": true + "get": { + "summary": "Read blogs", + "tags": ["Blogs"], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "imgsrc": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "user": { "type": "string" } + } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + } + } } - ], - "responses": { - "200": { - "description": "OK" + }, + "/api/blogs/{id}": { + "get": { + "summary": "Read a single blog", + "tags": ["Blogs"], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Blog ID", + "required": true, + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "data": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "imgsrc": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "user": { "type": "string" } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + }, + "404": { + "description": "Blog not found", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + } + } }, - "400": { - "description": "Bad Request" - } - } - }, - "delete": { - "summary": "Delete a blog", - "tags": ["Blogs"], - "parameters": [ - { - "name": "token", - "in": "header", - "type": "string", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" + "put": { + "summary": "Update a blog", + "tags": ["Blogs"], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Blog ID", + "required": true, + "schema": { "type": "string" } + }, + { + + "schema": { "type": "string" } + } + ], + "requestBody": { + "required": true, + "content": { + "multipart/form-data": { + "schema": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "image": { "type": "string", "format": "binary" } + } + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "data": { + "type": "object", + "properties": { + "title": { "type": "string" }, + "imgsrc": { "type": "string" }, + "desc": { "type": "string" }, + "content": { "type": "string" }, + "user": { "type": "string" } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + } + } }, - "400": { - "description": "Bad Request" + "delete": { + "summary": "Delete a blog", + "tags": ["Blogs"], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Blog ID", + "required": true, + "schema": { "type": "string" } + }, + { + + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "data": { "type": "object" } + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + }, + "404": { + "description": "Blog not found", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { "type": "string" }, + "message": { "type": "string" } + } + } + } + } + } + } } - } - } - }, + }, + + + "/api/blogs/{id}/comments": { "post": { "summary": "Add a comment to a blog", @@ -584,12 +794,7 @@ "summary": "Read a single user query", "tags": ["Queries"], "parameters": [ - { - "name": "token", - "in": "header", - "type": "string", - "required": true - }, + { "name": "id", "in": "path", @@ -610,12 +815,7 @@ "summary": "Delete a user query", "tags": ["Queries"], "parameters": [ - { - "name": "token", - "in": "header", - "type": "string", - "required": true - }, + { "name": "id", "in": "path", @@ -635,3 +835,5 @@ } } } + +