From 51b4d424921c17df8ac0d54b7aa6745fb7fc54e3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Feb 2022 19:55:37 +0000 Subject: [PATCH] Adding a structure for breaking up examples and parameters. --- packages/server/specs/examples.js | 39 ++++++++++++++++ packages/server/specs/generate.js | 45 +++---------------- packages/server/specs/openapi.json | 43 ++++++++++++++---- packages/server/specs/openapi.yaml | 31 +++++++++---- packages/server/specs/parameters.js | 10 +++++ packages/server/src/api/routes/public/rows.js | 25 +++++++---- 6 files changed, 131 insertions(+), 62 deletions(-) create mode 100644 packages/server/specs/examples.js create mode 100644 packages/server/specs/parameters.js diff --git a/packages/server/specs/examples.js b/packages/server/specs/examples.js new file mode 100644 index 0000000000..855ea16bab --- /dev/null +++ b/packages/server/specs/examples.js @@ -0,0 +1,39 @@ +exports.table = { + value: { + _id: "ta_5b1649e42a5b41dea4ef7742a36a7a70", + name: "People", + schema: { + name: { + type: "string", + name: "name", + }, + age: { + type: "number", + name: "age", + }, + relationship: { + type: "link", + name: "relationship", + tableId: "ta_...", + fieldName: "relatedColumn", + relationshipType: "many-to-many", + }, + }, + }, +} + +exports.row = { + value: { + _id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", + type: "row", + tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", + name: "Mike", + age: 30, + relationship: [ + { + primaryDisplay: "Joe", + _id: "ro_ta_...", + }, + ], + }, +} diff --git a/packages/server/specs/generate.js b/packages/server/specs/generate.js index 0298d8af20..b6f227e30e 100644 --- a/packages/server/specs/generate.js +++ b/packages/server/specs/generate.js @@ -1,6 +1,8 @@ const swaggerJsdoc = require("swagger-jsdoc") const { join } = require("path") const { writeFileSync } = require("fs") +const { row, table } = require("./examples") +const { tableId } = require("./parameters") const VARIABLES = {} @@ -23,45 +25,12 @@ const options = { }, ], components: { + parameters: { + tableId: tableId, + }, examples: { - row: { - value: { - _id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", - type: "row", - tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", - name: "Mike", - age: 30, - relationship: [ - { - primaryDisplay: "Joe", - _id: "ro_ta_...", - }, - ], - }, - }, - table: { - value: { - _id: "ta_5b1649e42a5b41dea4ef7742a36a7a70", - name: "People", - schema: { - name: { - type: "string", - name: "name", - }, - age: { - type: "number", - name: "age", - }, - relationship: { - type: "link", - name: "relationship", - tableId: "ta_...", - fieldName: "relatedColumn", - relationshipType: "many-to-many", - }, - }, - }, - }, + row: row, + table: table, }, }, }, diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index cccd836a23..76fa784877 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -16,6 +16,17 @@ } ], "components": { + "parameters": { + "tableId": { + "in": "path", + "name": "tableId", + "required": true, + "description": "The ID of the table which contains the rows which are being searched for.", + "schema": { + "type": "string" + } + } + }, "examples": { "row": { "value": { @@ -58,18 +69,12 @@ } }, "paths": { - "/row/{tableId}/search": { + "/tables/{tableId}/rows/search": { "post": { "summary": "Allows searching for rows within a table.", "parameters": [ { - "in": "path", - "name": "tableId", - "required": true, - "description": "The ID of the table which contains the rows which are being searched for.", - "schema": { - "type": "string" - } + "$ref": "#/components/parameters/tableId" } ], "requestBody": { @@ -214,6 +219,28 @@ } } } + }, + "/tables/{tableId}/rows": { + "post": { + "summary": "Allows creating a row within a specified table.", + "parameters": [ + { + "$ref": "#/components/parameters/tableId" + } + ], + "responses": { + "200": { + "description": "Returns the created row, including the ID which has been generated for it.", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } } }, "tags": [] diff --git a/packages/server/specs/openapi.yaml b/packages/server/specs/openapi.yaml index 4cd370001d..6b4328fef3 100644 --- a/packages/server/specs/openapi.yaml +++ b/packages/server/specs/openapi.yaml @@ -9,6 +9,14 @@ servers: - url: "{protocol}://{hostname}:10000/api/public/v1" description: Budibase self hosted API components: + parameters: + tableId: + in: path + name: tableId + required: true + description: The ID of the table which contains the rows which are being searched for. + schema: + type: string examples: row: value: @@ -38,17 +46,11 @@ components: fieldName: relatedColumn relationshipType: many-to-many paths: - "/row/{tableId}/search": + "/tables/{tableId}/rows/search": post: summary: Allows searching for rows within a table. parameters: - - in: path - name: tableId - required: true - description: The ID of the table which contains the rows which are being - searched for. - schema: - type: string + - $ref: "#/components/parameters/tableId" requestBody: required: true content: @@ -157,4 +159,17 @@ paths: description: If pagination in use, this will determine if there is another page to fetch. type: boolean + "/tables/{tableId}/rows": + post: + summary: Allows creating a row within a specified table. + parameters: + - $ref: "#/components/parameters/tableId" + responses: + "200": + description: Returns the created row, including the ID which has been generated + for it. + content: + application/json: + schema: + type: object tags: [] diff --git a/packages/server/specs/parameters.js b/packages/server/specs/parameters.js new file mode 100644 index 0000000000..a01bd6f3b8 --- /dev/null +++ b/packages/server/specs/parameters.js @@ -0,0 +1,10 @@ +exports.tableId = { + in: "path", + name: "tableId", + required: true, + description: + "The ID of the table which contains the rows which are being searched for.", + schema: { + type: "string", + }, +} diff --git a/packages/server/src/api/routes/public/rows.js b/packages/server/src/api/routes/public/rows.js index f4c59eaf9f..e1e558a7f9 100644 --- a/packages/server/src/api/routes/public/rows.js +++ b/packages/server/src/api/routes/public/rows.js @@ -5,17 +5,11 @@ const router = Router() /** * @openapi - * /row/{tableId}/search: + * /tables/{tableId}/rows/search: * post: * summary: Allows searching for rows within a table. * parameters: - * - in: path - * name: tableId - * required: true - * description: The ID of the table which contains the rows - * which are being searched for. - * schema: - * type: string + * - $ref: '#/components/parameters/tableId' * requestBody: * required: true * content: @@ -119,6 +113,21 @@ const router = Router() */ router.post("/tables/:tableId/rows/search", controller.search) +/** + * @openapi + * /tables/{tableId}/rows: + * post: + * summary: Allows creating a row within a specified table. + * parameters: + * - $ref: '#/components/parameters/tableId' + * responses: + * 200: + * description: Returns the created row, including the ID which has been generated for it. + * content: + * application/json: + * schema: + * type: object + */ router.post("/tables/:tableId/rows", controller.create) router.put("/tables/:tableId/rows/:rowId", controller.update)