From 7443a1745887c333cf126c25827204c22867211b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 21 Feb 2022 19:04:13 +0000 Subject: [PATCH] Adding in all endpoints/open API definitions, need to flesh everything out. --- packages/server/specs/openapi.json | 325 ++++++++++++++++-- packages/server/specs/openapi.yaml | 187 +++++++++- packages/server/specs/parameters.js | 30 ++ packages/server/specs/schemas.js | 15 + .../api/controllers/public/applications.js | 15 + .../src/api/controllers/public/tables.js | 4 - .../src/api/controllers/public/users.js | 15 + .../src/api/routes/public/applications.js | 79 +++++ .../server/src/api/routes/public/queries.js | 23 ++ .../server/src/api/routes/public/tables.js | 23 -- .../server/src/api/routes/public/users.js | 81 +++++ 11 files changed, 720 insertions(+), 77 deletions(-) create mode 100644 packages/server/src/api/controllers/public/applications.js create mode 100644 packages/server/src/api/controllers/public/users.js diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index beb1eaeb65..12ac1f05be 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -43,6 +43,33 @@ "schema": { "type": "string" } + }, + "appIdUrl": { + "in": "path", + "name": "appId", + "required": true, + "description": "The ID of the app which this request is targeting.", + "schema": { + "type": "string" + } + }, + "queryId": { + "in": "path", + "name": "queryId", + "required": true, + "description": "The ID of the query which this request is targeting.", + "schema": { + "type": "string" + } + }, + "userId": { + "in": "path", + "name": "userId", + "required": true, + "description": "The ID of the user which this request is targeting.", + "schema": { + "type": "string" + } } }, "examples": { @@ -366,6 +393,18 @@ ] } } + }, + "query": { + "type": "object", + "properties": {} + }, + "user": { + "type": "object", + "properties": {} + }, + "application": { + "type": "object", + "properties": {} } } }, @@ -375,12 +414,133 @@ } ], "paths": { + "/applications/search": { + "post": { + "summary": "Search for an application based on its app name.", + "tags": [ + "applications" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the applications that were found based on the search parameters.", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/application" + } + } + } + } + } + } + } + }, + "/applications": { + "post": { + "summary": "Create a new application.", + "tags": [ + "applications" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the created application.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } + }, + "/applications/{appId}": { + "put": { + "summary": "Update an existing application by its ID.", + "tags": [ + "applications" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appIdUrl" + } + ], + "responses": { + "200": { + "description": "Returns the updated application.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + }, + "delete": { + "summary": "Delete an existing application by its ID.", + "tags": [ + "applications" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appIdUrl" + } + ], + "responses": { + "200": { + "description": "Returns the deleted application.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } + }, "/queries/search": { "post": { "summary": "Search for a query based on its name.", "tags": [ "queries" - ] + ], + "parameters": [ + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the queries found based on the search parameters.", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/query" + } + } + } + } + } + } } }, "/queries/{queryId}": { @@ -388,7 +548,30 @@ "summary": "Execute a query and retrieve its response.", "tags": [ "queries" - ] + ], + "parameters": [ + { + "$ref": "#/components/parameters/queryId" + }, + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the result of the query execution.", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object" + } + } + } + } + } + } } }, "/tables/{tableId}/rows/search": { @@ -866,37 +1049,6 @@ } }, "/tables/{tableId}": { - "get": { - "summary": "Get a single table by its ID, internal and external within an app.", - "tags": [ - "tables" - ], - "parameters": [ - { - "$ref": "#/components/parameters/tableId" - }, - { - "$ref": "#/components/parameters/appId" - } - ], - "responses": { - "200": { - "description": "Returns the table that was found.", - "content": { - "application/json": { - "schema": { - "type": "object" - }, - "examples": { - "table": { - "$ref": "#/components/examples/row" - } - } - } - } - } - } - }, "delete": { "summary": "Delete a single table and all of its data.", "tags": [ @@ -928,6 +1080,113 @@ } } } + }, + "/users/search": { + "post": { + "summary": "Search for a user based on their email/username.", + "tags": [ + "users" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the found users based on search parameters.", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/user" + } + } + } + } + } + } + } + }, + "/users": { + "post": { + "summary": "Create a new user in the Budibase portal.", + "tags": [ + "users" + ], + "parameters": [ + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the created user.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } + }, + "/users/{userId}": { + "put": { + "summary": "Update an existing user by their ID.", + "tags": [ + "users" + ], + "parameters": [ + { + "$ref": "#/components/parameters/userId" + }, + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the updated user.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + }, + "delete": { + "summary": "Delete an existing user by their ID.", + "tags": [ + "users" + ], + "parameters": [ + { + "$ref": "#/components/parameters/userId" + }, + { + "$ref": "#/components/parameters/appId" + } + ], + "responses": { + "200": { + "description": "Returns the deleted user.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } } }, "tags": [] diff --git a/packages/server/specs/openapi.yaml b/packages/server/specs/openapi.yaml index 04b25647f1..0656243067 100644 --- a/packages/server/specs/openapi.yaml +++ b/packages/server/specs/openapi.yaml @@ -31,6 +31,27 @@ components: description: The ID of the app which this request is targeting. schema: type: string + appIdUrl: + in: path + name: appId + required: true + description: The ID of the app which this request is targeting. + schema: + type: string + queryId: + in: path + name: queryId + required: true + description: The ID of the query which this request is targeting. + schema: + type: string + userId: + in: path + name: userId + required: true + description: The ID of the user which this request is targeting. + schema: + type: string examples: table: value: @@ -267,19 +288,109 @@ components: autocolumn: type: boolean description: Defines whether the column is automatically generated. + query: + type: object + properties: {} + user: + type: object + properties: {} + application: + type: object + properties: {} security: - ApiKeyAuth: [] paths: + /applications/search: + post: + summary: Search for an application based on its app name. + tags: + - applications + parameters: + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the applications that were found based on the search + parameters. + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/application" + /applications: + post: + summary: Create a new application. + tags: + - applications + parameters: + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the created application. + content: + application/json: + schema: + type: object + "/applications/{appId}": + put: + summary: Update an existing application by its ID. + tags: + - applications + parameters: + - $ref: "#/components/parameters/appIdUrl" + responses: + "200": + description: Returns the updated application. + content: + application/json: + schema: + type: object + delete: + summary: Delete an existing application by its ID. + tags: + - applications + parameters: + - $ref: "#/components/parameters/appIdUrl" + responses: + "200": + description: Returns the deleted application. + content: + application/json: + schema: + type: object /queries/search: post: summary: Search for a query based on its name. tags: - queries + parameters: + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the queries found based on the search parameters. + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/query" "/queries/{queryId}": post: summary: Execute a query and retrieve its response. tags: - queries + parameters: + - $ref: "#/components/parameters/queryId" + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the result of the query execution. + content: + application/json: + schema: + type: array + items: + type: object "/tables/{tableId}/rows/search": post: summary: Used to search for rows within a table. @@ -580,23 +691,6 @@ paths: table: $ref: "#/components/examples/row" "/tables/{tableId}": - get: - summary: Get a single table by its ID, internal and external within an app. - tags: - - tables - parameters: - - $ref: "#/components/parameters/tableId" - - $ref: "#/components/parameters/appId" - responses: - "200": - description: Returns the table that was found. - content: - application/json: - schema: - type: object - examples: - table: - $ref: "#/components/examples/row" delete: summary: Delete a single table and all of its data. tags: @@ -614,4 +708,63 @@ paths: examples: table: $ref: "#/components/examples/table" + /users/search: + post: + summary: Search for a user based on their email/username. + tags: + - users + parameters: + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the found users based on search parameters. + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/user" + /users: + post: + summary: Create a new user in the Budibase portal. + tags: + - users + parameters: + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the created user. + content: + application/json: + schema: + type: object + "/users/{userId}": + put: + summary: Update an existing user by their ID. + tags: + - users + parameters: + - $ref: "#/components/parameters/userId" + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the updated user. + content: + application/json: + schema: + type: object + delete: + summary: Delete an existing user by their ID. + tags: + - users + parameters: + - $ref: "#/components/parameters/userId" + - $ref: "#/components/parameters/appId" + responses: + "200": + description: Returns the deleted user. + content: + application/json: + schema: + type: object tags: [] diff --git a/packages/server/specs/parameters.js b/packages/server/specs/parameters.js index f1382ffe71..ca7a0a9a27 100644 --- a/packages/server/specs/parameters.js +++ b/packages/server/specs/parameters.js @@ -27,3 +27,33 @@ exports.appId = { type: "string", }, } + +exports.appIdUrl = { + in: "path", + name: "appId", + required: true, + description: "The ID of the app which this request is targeting.", + schema: { + type: "string", + }, +} + +exports.queryId = { + in: "path", + name: "queryId", + required: true, + description: "The ID of the query which this request is targeting.", + schema: { + type: "string", + }, +} + +exports.userId = { + in: "path", + name: "userId", + required: true, + description: "The ID of the user which this request is targeting.", + schema: { + type: "string", + }, +} diff --git a/packages/server/specs/schemas.js b/packages/server/specs/schemas.js index f9fedda89f..0dd4e2512d 100644 --- a/packages/server/specs/schemas.js +++ b/packages/server/specs/schemas.js @@ -143,3 +143,18 @@ exports.table = { }, }, } + +exports.query = { + type: "object", + properties: {}, +} + +exports.user = { + type: "object", + properties: {}, +} + +exports.application = { + type: "object", + properties: {}, +} diff --git a/packages/server/src/api/controllers/public/applications.js b/packages/server/src/api/controllers/public/applications.js new file mode 100644 index 0000000000..8bd8d6d9d2 --- /dev/null +++ b/packages/server/src/api/controllers/public/applications.js @@ -0,0 +1,15 @@ +exports.search = () => { + +} + +exports.create = () => { + +} + +exports.update = () => { + +} + +exports.delete = () => { + +} \ No newline at end of file diff --git a/packages/server/src/api/controllers/public/tables.js b/packages/server/src/api/controllers/public/tables.js index 7c2fad4102..8bd8d6d9d2 100644 --- a/packages/server/src/api/controllers/public/tables.js +++ b/packages/server/src/api/controllers/public/tables.js @@ -6,10 +6,6 @@ exports.create = () => { } -exports.singleRead = () => { - -} - exports.update = () => { } diff --git a/packages/server/src/api/controllers/public/users.js b/packages/server/src/api/controllers/public/users.js new file mode 100644 index 0000000000..8bd8d6d9d2 --- /dev/null +++ b/packages/server/src/api/controllers/public/users.js @@ -0,0 +1,15 @@ +exports.search = () => { + +} + +exports.create = () => { + +} + +exports.update = () => { + +} + +exports.delete = () => { + +} \ No newline at end of file diff --git a/packages/server/src/api/routes/public/applications.js b/packages/server/src/api/routes/public/applications.js index f9a77e6bc5..193085b9a8 100644 --- a/packages/server/src/api/routes/public/applications.js +++ b/packages/server/src/api/routes/public/applications.js @@ -1,5 +1,84 @@ const Router = require("@koa/router") +const controller = require("../../controllers/public/applications") const router = Router() +/** + * @openapi + * /applications/search: + * post: + * summary: Search for an application based on its app name. + * tags: + * - applications + * parameters: + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the applications that were found based on the search parameters. + * content: + * application/json: + * schema: + * type: array + * items: + * $ref: '#/components/schemas/application' + */ +router.post("/applications/search", controller.search) + +/** + * @openapi + * /applications: + * post: + * summary: Create a new application. + * tags: + * - applications + * parameters: + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the created application. + * content: + * application/json: + * schema: + * type: object + */ +router.post("/applications", controller.create) + +/** + * @openapi + * /applications/{appId}: + * put: + * summary: Update an existing application by its ID. + * tags: + * - applications + * parameters: + * - $ref: '#/components/parameters/appIdUrl' + * responses: + * 200: + * description: Returns the updated application. + * content: + * application/json: + * schema: + * type: object + */ +router.put("/applications/:appId", controller.update) + +/** + * @openapi + * /applications/{appId}: + * delete: + * summary: Delete an existing application by its ID. + * tags: + * - applications + * parameters: + * - $ref: '#/components/parameters/appIdUrl' + * responses: + * 200: + * description: Returns the deleted application. + * content: + * application/json: + * schema: + * type: object + */ +router.delete("/applications/:appId", controller.delete) + module.exports = router diff --git a/packages/server/src/api/routes/public/queries.js b/packages/server/src/api/routes/public/queries.js index 113767946b..b1982562ac 100644 --- a/packages/server/src/api/routes/public/queries.js +++ b/packages/server/src/api/routes/public/queries.js @@ -10,6 +10,17 @@ const router = Router() * summary: Search for a query based on its name. * tags: * - queries + * parameters: + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the queries found based on the search parameters. + * content: + * application/json: + * schema: + * type: array + * items: + * $ref: '#/components/schemas/query' */ router.post("/queries/search", controller.search) @@ -20,6 +31,18 @@ router.post("/queries/search", controller.search) * summary: Execute a query and retrieve its response. * tags: * - queries + * parameters: + * - $ref: '#/components/parameters/queryId' + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the result of the query execution. + * content: + * application/json: + * schema: + * type: array + * items: + * type: object */ router.post("/queries/:queryId", controller.execute) diff --git a/packages/server/src/api/routes/public/tables.js b/packages/server/src/api/routes/public/tables.js index 748a7ca704..a2c26af496 100644 --- a/packages/server/src/api/routes/public/tables.js +++ b/packages/server/src/api/routes/public/tables.js @@ -99,29 +99,6 @@ router.post("/tables", controller.create) */ router.put("/tables/:tableId", controller.update) -/** - * @openapi - * /tables/{tableId}: - * get: - * summary: Get a single table by its ID, internal and external within an app. - * tags: - * - tables - * parameters: - * - $ref: '#/components/parameters/tableId' - * - $ref: '#/components/parameters/appId' - * responses: - * 200: - * description: Returns the table that was found. - * content: - * application/json: - * schema: - * type: object - * examples: - * table: - * $ref: '#/components/examples/row' - */ -router.get("/tables/:tableId", controller.singleRead) - /** * @openapi * /tables/{tableId}: diff --git a/packages/server/src/api/routes/public/users.js b/packages/server/src/api/routes/public/users.js index f9a77e6bc5..e76af6097c 100644 --- a/packages/server/src/api/routes/public/users.js +++ b/packages/server/src/api/routes/public/users.js @@ -1,5 +1,86 @@ const Router = require("@koa/router") +const controller = require("../../controllers/public/users") const router = Router() +/** + * @openapi + * /users/search: + * post: + * summary: Search for a user based on their email/username. + * tags: + * - users + * parameters: + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the found users based on search parameters. + * content: + * application/json: + * schema: + * type: array + * items: + * $ref: '#/components/schemas/user' + */ +router.post("/users/search", controller.search) + +/** + * @openapi + * /users: + * post: + * summary: Create a new user in the Budibase portal. + * tags: + * - users + * parameters: + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the created user. + * content: + * application/json: + * schema: + * type: object + */ +router.post("/users", controller.create) + +/** + * @openapi + * /users/{userId}: + * put: + * summary: Update an existing user by their ID. + * tags: + * - users + * parameters: + * - $ref: '#/components/parameters/userId' + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the updated user. + * content: + * application/json: + * schema: + * type: object + */ +router.put("/users/:userId", controller.update) + +/** + * @openapi + * /users/{userId}: + * delete: + * summary: Delete an existing user by their ID. + * tags: + * - users + * parameters: + * - $ref: '#/components/parameters/userId' + * - $ref: '#/components/parameters/appId' + * responses: + * 200: + * description: Returns the deleted user. + * content: + * application/json: + * schema: + * type: object + */ +router.delete("/users/:userId", controller.delete) + module.exports = router