From 948c520a6a840390d0e4aa7fdf8421501bb6a12b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 22 Feb 2022 15:06:08 +0000 Subject: [PATCH] Refactoring resource system, so that examples and schemas have individual files rather than all being lumped into one. --- packages/server/specs/examples.js | 184 -------- packages/server/specs/generate.js | 3 +- packages/server/specs/openapi.json | 388 +++++++++-------- packages/server/specs/openapi.yaml | 406 +++++++++--------- .../server/specs/resources/application.js | 38 ++ packages/server/specs/resources/index.js | 24 ++ packages/server/specs/resources/misc.js | 12 + packages/server/specs/resources/query.js | 56 +++ packages/server/specs/resources/row.js | 64 +++ .../specs/{schemas.js => resources/table.js} | 91 ++-- packages/server/specs/resources/user.js | 50 +++ .../server/specs/resources/utils/Resource.js | 26 ++ .../server/specs/resources/utils/index.js | 6 + .../server/src/api/routes/public/users.js | 12 + 14 files changed, 744 insertions(+), 616 deletions(-) delete mode 100644 packages/server/specs/examples.js create mode 100644 packages/server/specs/resources/application.js create mode 100644 packages/server/specs/resources/index.js create mode 100644 packages/server/specs/resources/misc.js create mode 100644 packages/server/specs/resources/query.js create mode 100644 packages/server/specs/resources/row.js rename packages/server/specs/{schemas.js => resources/table.js} (80%) create mode 100644 packages/server/specs/resources/user.js create mode 100644 packages/server/specs/resources/utils/Resource.js create mode 100644 packages/server/specs/resources/utils/index.js diff --git a/packages/server/specs/examples.js b/packages/server/specs/examples.js deleted file mode 100644 index ab245d5bbc..0000000000 --- a/packages/server/specs/examples.js +++ /dev/null @@ -1,184 +0,0 @@ -const baseRow = { - _id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", - type: "row", - tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", - name: "Mike", - age: 30, -} - -const inputRow = { - ...baseRow, - relationship: ["ro_ta_..."], -} - -const row = { - ...baseRow, - relationship: [ - { - primaryDisplay: "Joe", - _id: "ro_ta_...", - }, - ], -} - -const table = { - _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", - }, - }, -} - -const query = { - _id: "query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e", - datasourceId: "datasource_plus_4d8be0c506b9465daf4bf84d890fdab6", - parameters: [], - fields: { - sql: "select * from persons", - }, - queryVerb: "read", - name: "Help", - schema: { - personid: { - name: "personid", - type: "string", - }, - lastname: { - name: "lastname", - type: "string", - }, - firstname: { - name: "firstname", - type: "string", - }, - address: { - name: "address", - type: "string", - }, - city: { - name: "city", - type: "string", - }, - }, - transformer: "return data", - readable: true, -} - -const user = { - _id: "us_693a73206518477283a8d5ae31103252", - email: "test@test.com", - roles: { - app_957b12f943d348faa61db7e18e088d0f: "BASIC", - }, - builder: { - global: false, - }, - admin: { - global: true, - }, - tenantId: "default", - status: "active", - budibaseAccess: true, - csrfToken: "9c70291d-7137-48f9-9166-99ab5473a3d4", - userId: "us_693a73206518477283a8d5ae31103252", - roleId: "ADMIN", - role: { - _id: "ADMIN", - name: "Admin", - permissionId: "admin", - inherits: "POWER", - }, -} - -const application = { - _id: "app_metadata", - appId: "app_dev_957b12f943d348faa61db7e18e088d0f", - version: "1.0.58-alpha.0", - name: "App name", - url: "/app-url", - tenantId: "default", - updatedAt: "2022-02-22T13:00:54.035Z", - createdAt: "2022-02-11T18:02:26.961Z", - status: "development", - lockedBy: user, -} - -exports.table = { - value: { - table: table, - }, -} - -exports.tables = { - value: { - tables: [table], - }, -} - -exports.inputRow = { - value: inputRow, -} - -exports.row = { - value: { - row: row, - }, -} - -exports.rows = { - value: { - rows: [row], - hasNextPage: true, - bookmark: 10, - }, -} - -exports.user = { - value: { - user: user, - }, -} - -exports.users = { - value: { - users: [user], - }, -} - -exports.query = { - value: { - query: query, - }, -} - -exports.queries = { - value: { - queries: [query], - }, -} - -exports.application = { - value: { - application: application, - }, -} - -exports.applications = { - value: { - applications: [application], - }, -} diff --git a/packages/server/specs/generate.js b/packages/server/specs/generate.js index b940ae6642..eaace0fee3 100644 --- a/packages/server/specs/generate.js +++ b/packages/server/specs/generate.js @@ -1,10 +1,9 @@ const swaggerJsdoc = require("swagger-jsdoc") const { join } = require("path") const { writeFileSync } = require("fs") -const examples = require("./examples") +const { examples, schemas } = require("./resources") const parameters = require("./parameters") const security = require("./security") -const schemas = require("./schemas") const VARIABLES = {} diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index e6ba7ce8ef..6bf9f5a78f 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -73,52 +73,82 @@ } }, "examples": { - "table": { + "application": { "value": { - "table": { - "_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70", - "name": "People", - "schema": { - "name": { - "type": "string", - "name": "name" + "application": { + "_id": "app_metadata", + "appId": "app_dev_957b12f943d348faa61db7e18e088d0f", + "version": "1.0.58-alpha.0", + "name": "App name", + "url": "/app-url", + "tenantId": "default", + "updatedAt": "2022-02-22T13:00:54.035Z", + "createdAt": "2022-02-11T18:02:26.961Z", + "status": "development", + "lockedBy": { + "_id": "us_693a73206518477283a8d5ae31103252", + "email": "test@test.com", + "roles": { + "app_957b12f943d348faa61db7e18e088d0f": "BASIC" }, - "age": { - "type": "number", - "name": "age" + "builder": { + "global": false }, - "relationship": { - "type": "link", - "name": "relationship", - "tableId": "ta_...", - "fieldName": "relatedColumn", - "relationshipType": "many-to-many" + "admin": { + "global": true + }, + "tenantId": "default", + "status": "active", + "budibaseAccess": true, + "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", + "userId": "us_693a73206518477283a8d5ae31103252", + "roleId": "ADMIN", + "role": { + "_id": "ADMIN", + "name": "Admin", + "permissionId": "admin", + "inherits": "POWER" } } } } }, - "tables": { + "applications": { "value": { - "tables": [ + "applications": [ { - "_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70", - "name": "People", - "schema": { - "name": { - "type": "string", - "name": "name" + "_id": "app_metadata", + "appId": "app_dev_957b12f943d348faa61db7e18e088d0f", + "version": "1.0.58-alpha.0", + "name": "App name", + "url": "/app-url", + "tenantId": "default", + "updatedAt": "2022-02-22T13:00:54.035Z", + "createdAt": "2022-02-11T18:02:26.961Z", + "status": "development", + "lockedBy": { + "_id": "us_693a73206518477283a8d5ae31103252", + "email": "test@test.com", + "roles": { + "app_957b12f943d348faa61db7e18e088d0f": "BASIC" }, - "age": { - "type": "number", - "name": "age" + "builder": { + "global": false }, - "relationship": { - "type": "link", - "name": "relationship", - "tableId": "ta_...", - "fieldName": "relatedColumn", - "relationshipType": "many-to-many" + "admin": { + "global": true + }, + "tenantId": "default", + "status": "active", + "budibaseAccess": true, + "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", + "userId": "us_693a73206518477283a8d5ae31103252", + "roleId": "ADMIN", + "role": { + "_id": "ADMIN", + "name": "Admin", + "permissionId": "admin", + "inherits": "POWER" } } } @@ -175,61 +205,53 @@ "bookmark": 10 } }, - "user": { + "table": { "value": { - "user": { - "_id": "us_693a73206518477283a8d5ae31103252", - "email": "test@test.com", - "roles": { - "app_957b12f943d348faa61db7e18e088d0f": "BASIC" - }, - "builder": { - "global": false - }, - "admin": { - "global": true - }, - "tenantId": "default", - "status": "active", - "budibaseAccess": true, - "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", - "userId": "us_693a73206518477283a8d5ae31103252", - "roleId": "ADMIN", - "role": { - "_id": "ADMIN", - "name": "Admin", - "permissionId": "admin", - "inherits": "POWER" + "table": { + "_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" + } } } } }, - "users": { + "tables": { "value": { - "users": [ + "tables": [ { - "_id": "us_693a73206518477283a8d5ae31103252", - "email": "test@test.com", - "roles": { - "app_957b12f943d348faa61db7e18e088d0f": "BASIC" - }, - "builder": { - "global": false - }, - "admin": { - "global": true - }, - "tenantId": "default", - "status": "active", - "budibaseAccess": true, - "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", - "userId": "us_693a73206518477283a8d5ae31103252", - "roleId": "ADMIN", - "role": { - "_id": "ADMIN", - "name": "Admin", - "permissionId": "admin", - "inherits": "POWER" + "_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" + } } } ] @@ -313,19 +335,39 @@ ] } }, - "application": { + "user": { "value": { - "application": { - "_id": "app_metadata", - "appId": "app_dev_957b12f943d348faa61db7e18e088d0f", - "version": "1.0.58-alpha.0", - "name": "App name", - "url": "/app-url", + "user": { + "_id": "us_693a73206518477283a8d5ae31103252", + "email": "test@test.com", + "roles": { + "app_957b12f943d348faa61db7e18e088d0f": "BASIC" + }, + "builder": { + "global": false + }, + "admin": { + "global": true + }, "tenantId": "default", - "updatedAt": "2022-02-22T13:00:54.035Z", - "createdAt": "2022-02-11T18:02:26.961Z", - "status": "development", - "lockedBy": { + "status": "active", + "budibaseAccess": true, + "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", + "userId": "us_693a73206518477283a8d5ae31103252", + "roleId": "ADMIN", + "role": { + "_id": "ADMIN", + "name": "Admin", + "permissionId": "admin", + "inherits": "POWER" + } + } + } + }, + "users": { + "value": { + "users": [ + { "_id": "us_693a73206518477283a8d5ae31103252", "email": "test@test.com", "roles": { @@ -350,48 +392,6 @@ "inherits": "POWER" } } - } - } - }, - "applications": { - "value": { - "applications": [ - { - "_id": "app_metadata", - "appId": "app_dev_957b12f943d348faa61db7e18e088d0f", - "version": "1.0.58-alpha.0", - "name": "App name", - "url": "/app-url", - "tenantId": "default", - "updatedAt": "2022-02-22T13:00:54.035Z", - "createdAt": "2022-02-11T18:02:26.961Z", - "status": "development", - "lockedBy": { - "_id": "us_693a73206518477283a8d5ae31103252", - "email": "test@test.com", - "roles": { - "app_957b12f943d348faa61db7e18e088d0f": "BASIC" - }, - "builder": { - "global": false - }, - "admin": { - "global": true - }, - "tenantId": "default", - "status": "active", - "budibaseAccess": true, - "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", - "userId": "us_693a73206518477283a8d5ae31103252", - "roleId": "ADMIN", - "role": { - "_id": "ADMIN", - "name": "Admin", - "permissionId": "admin", - "inherits": "POWER" - } - } - } ] } } @@ -405,6 +405,19 @@ } }, "schemas": { + "application": { + "type": "object", + "properties": {} + }, + "applicationOutput": { + "type": "object", + "properties": { + "application": { + "type": "object", + "properties": {} + } + } + }, "row": { "description": "The row to be created/updated, based on the table schema.", "type": "object", @@ -428,6 +441,34 @@ ] } }, + "rowOutput": { + "type": "object", + "properties": { + "row": { + "description": "The row to be created/updated, based on the table schema.", + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object" + }, + { + "type": "integer" + }, + { + "type": "array" + }, + { + "type": "boolean" + } + ] + } + } + } + }, "table": { "description": "The table to be created/updated.", "type": "object", @@ -620,27 +661,6 @@ } } }, - "query": { - "type": "object", - "properties": {} - }, - "user": { - "type": "object", - "properties": {} - }, - "application": { - "type": "object", - "properties": {} - }, - "applicationOutput": { - "type": "object", - "properties": { - "application": { - "type": "object", - "properties": {} - } - } - }, "tableOutput": { "type": "object", "properties": { @@ -838,6 +858,14 @@ } } }, + "query": { + "type": "object", + "properties": {} + }, + "user": { + "type": "object", + "properties": {} + }, "userOutput": { "type": "object", "properties": { @@ -847,34 +875,6 @@ } } }, - "rowOutput": { - "type": "object", - "properties": { - "row": { - "description": "The row to be created/updated, based on the table schema.", - "type": "object", - "additionalProperties": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "object" - }, - { - "type": "integer" - }, - { - "type": "array" - }, - { - "type": "boolean" - } - ] - } - } - } - }, "nameSearch": { "type": "object", "properties": { @@ -1750,6 +1750,16 @@ "$ref": "#/components/parameters/appId" } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/user" + } + } + } + }, "responses": { "200": { "description": "Returns the created user.", @@ -1783,6 +1793,16 @@ "$ref": "#/components/parameters/appId" } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/user" + } + } + } + }, "responses": { "200": { "description": "Returns the updated user.", diff --git a/packages/server/specs/openapi.yaml b/packages/server/specs/openapi.yaml index fd12dd2b22..a38e91aa39 100644 --- a/packages/server/specs/openapi.yaml +++ b/packages/server/specs/openapi.yaml @@ -53,175 +53,6 @@ components: schema: type: string examples: - table: - value: - table: - _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 - tables: - value: - tables: - - _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 - inputRow: - value: - _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 - type: row - tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 - name: Mike - age: 30 - relationship: - - ro_ta_... - row: - value: - row: - _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 - type: row - tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 - name: Mike - age: 30 - relationship: - - primaryDisplay: Joe - _id: ro_ta_... - rows: - value: - rows: - - _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 - type: row - tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 - name: Mike - age: 30 - relationship: - - primaryDisplay: Joe - _id: ro_ta_... - hasNextPage: true - bookmark: 10 - user: - value: - user: - _id: us_693a73206518477283a8d5ae31103252 - email: test@test.com - roles: - app_957b12f943d348faa61db7e18e088d0f: BASIC - builder: - global: false - admin: - global: true - tenantId: default - status: active - budibaseAccess: true - csrfToken: 9c70291d-7137-48f9-9166-99ab5473a3d4 - userId: us_693a73206518477283a8d5ae31103252 - roleId: ADMIN - role: - _id: ADMIN - name: Admin - permissionId: admin - inherits: POWER - users: - value: - users: - - _id: us_693a73206518477283a8d5ae31103252 - email: test@test.com - roles: - app_957b12f943d348faa61db7e18e088d0f: BASIC - builder: - global: false - admin: - global: true - tenantId: default - status: active - budibaseAccess: true - csrfToken: 9c70291d-7137-48f9-9166-99ab5473a3d4 - userId: us_693a73206518477283a8d5ae31103252 - roleId: ADMIN - role: - _id: ADMIN - name: Admin - permissionId: admin - inherits: POWER - query: - value: - query: - _id: query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e - datasourceId: datasource_plus_4d8be0c506b9465daf4bf84d890fdab6 - parameters: [] - fields: - sql: select * from persons - queryVerb: read - name: Help - schema: - personid: - name: personid - type: string - lastname: - name: lastname - type: string - firstname: - name: firstname - type: string - address: - name: address - type: string - city: - name: city - type: string - transformer: return data - readable: true - queries: - value: - queries: - - _id: query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e - datasourceId: datasource_plus_4d8be0c506b9465daf4bf84d890fdab6 - parameters: [] - fields: - sql: select * from persons - queryVerb: read - name: Help - schema: - personid: - name: personid - type: string - lastname: - name: lastname - type: string - firstname: - name: firstname - type: string - address: - name: address - type: string - city: - name: city - type: string - transformer: return data - readable: true application: value: application: @@ -286,6 +117,175 @@ components: name: Admin permissionId: admin inherits: POWER + inputRow: + value: + _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 + type: row + tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 + name: Mike + age: 30 + relationship: + - ro_ta_... + row: + value: + row: + _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 + type: row + tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 + name: Mike + age: 30 + relationship: + - primaryDisplay: Joe + _id: ro_ta_... + rows: + value: + rows: + - _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4 + type: row + tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70 + name: Mike + age: 30 + relationship: + - primaryDisplay: Joe + _id: ro_ta_... + hasNextPage: true + bookmark: 10 + table: + value: + table: + _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 + tables: + value: + tables: + - _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 + query: + value: + query: + _id: query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e + datasourceId: datasource_plus_4d8be0c506b9465daf4bf84d890fdab6 + parameters: [] + fields: + sql: select * from persons + queryVerb: read + name: Help + schema: + personid: + name: personid + type: string + lastname: + name: lastname + type: string + firstname: + name: firstname + type: string + address: + name: address + type: string + city: + name: city + type: string + transformer: return data + readable: true + queries: + value: + queries: + - _id: query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e + datasourceId: datasource_plus_4d8be0c506b9465daf4bf84d890fdab6 + parameters: [] + fields: + sql: select * from persons + queryVerb: read + name: Help + schema: + personid: + name: personid + type: string + lastname: + name: lastname + type: string + firstname: + name: firstname + type: string + address: + name: address + type: string + city: + name: city + type: string + transformer: return data + readable: true + user: + value: + user: + _id: us_693a73206518477283a8d5ae31103252 + email: test@test.com + roles: + app_957b12f943d348faa61db7e18e088d0f: BASIC + builder: + global: false + admin: + global: true + tenantId: default + status: active + budibaseAccess: true + csrfToken: 9c70291d-7137-48f9-9166-99ab5473a3d4 + userId: us_693a73206518477283a8d5ae31103252 + roleId: ADMIN + role: + _id: ADMIN + name: Admin + permissionId: admin + inherits: POWER + users: + value: + users: + - _id: us_693a73206518477283a8d5ae31103252 + email: test@test.com + roles: + app_957b12f943d348faa61db7e18e088d0f: BASIC + builder: + global: false + admin: + global: true + tenantId: default + status: active + budibaseAccess: true + csrfToken: 9c70291d-7137-48f9-9166-99ab5473a3d4 + userId: us_693a73206518477283a8d5ae31103252 + roleId: ADMIN + role: + _id: ADMIN + name: Admin + permissionId: admin + inherits: POWER securitySchemes: ApiKeyAuth: type: apiKey @@ -294,6 +294,15 @@ components: description: Your individual API key, this will provide access based on the configured RBAC settings of your user. schemas: + application: + type: object + properties: {} + applicationOutput: + type: object + properties: + application: + type: object + properties: {} row: description: The row to be created/updated, based on the table schema. type: object @@ -304,6 +313,19 @@ components: - type: integer - type: array - type: boolean + rowOutput: + type: object + properties: + row: + description: The row to be created/updated, based on the table schema. + type: object + additionalProperties: + oneOf: + - type: string + - type: object + - type: integer + - type: array + - type: boolean table: description: The table to be created/updated. type: object @@ -455,21 +477,6 @@ components: autocolumn: type: boolean description: Defines whether the column is automatically generated. - query: - type: object - properties: {} - user: - type: object - properties: {} - application: - type: object - properties: {} - applicationOutput: - type: object - properties: - application: - type: object - properties: {} tableOutput: type: object properties: @@ -626,25 +633,18 @@ components: autocolumn: type: boolean description: Defines whether the column is automatically generated. + query: + type: object + properties: {} + user: + type: object + properties: {} userOutput: type: object properties: user: type: object properties: {} - rowOutput: - type: object - properties: - row: - description: The row to be created/updated, based on the table schema. - type: object - additionalProperties: - oneOf: - - type: string - - type: object - - type: integer - - type: array - - type: boolean nameSearch: type: object properties: @@ -1174,6 +1174,12 @@ paths: - users parameters: - $ref: "#/components/parameters/appId" + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/user" responses: "200": description: Returns the created user. @@ -1192,6 +1198,12 @@ paths: parameters: - $ref: "#/components/parameters/userId" - $ref: "#/components/parameters/appId" + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/user" responses: "200": description: Returns the updated user. diff --git a/packages/server/specs/resources/application.js b/packages/server/specs/resources/application.js new file mode 100644 index 0000000000..d3d063b8de --- /dev/null +++ b/packages/server/specs/resources/application.js @@ -0,0 +1,38 @@ +const userResource = require("./user") +const { object } = require("./utils") +const Resource = require("./utils/Resource") + +const application = { + _id: "app_metadata", + appId: "app_dev_957b12f943d348faa61db7e18e088d0f", + version: "1.0.58-alpha.0", + name: "App name", + url: "/app-url", + tenantId: "default", + updatedAt: "2022-02-22T13:00:54.035Z", + createdAt: "2022-02-11T18:02:26.961Z", + status: "development", + lockedBy: userResource.getExamples().user.value.user, +} + +const applicationSchema = object({}) + +module.exports = new Resource() + .setExamples({ + application: { + value: { + application: application, + }, + }, + applications: { + value: { + applications: [application], + }, + }, + }) + .setSchemas({ + application: applicationSchema, + applicationOutput: object({ + application: applicationSchema, + }), + }) diff --git a/packages/server/specs/resources/index.js b/packages/server/specs/resources/index.js new file mode 100644 index 0000000000..67421fa494 --- /dev/null +++ b/packages/server/specs/resources/index.js @@ -0,0 +1,24 @@ +const application = require("./application") +const row = require("./row") +const table = require("./table") +const query = require("./query") +const user = require("./user") +const misc = require("./misc") + +exports.examples = { + ...application.getExamples(), + ...row.getExamples(), + ...table.getExamples(), + ...query.getExamples(), + ...user.getExamples(), + ...misc.getExamples(), +} + +exports.schemas = { + ...application.getSchemas(), + ...row.getSchemas(), + ...table.getSchemas(), + ...query.getSchemas(), + ...user.getSchemas(), + ...misc.getSchemas(), +} diff --git a/packages/server/specs/resources/misc.js b/packages/server/specs/resources/misc.js new file mode 100644 index 0000000000..bf92680ca8 --- /dev/null +++ b/packages/server/specs/resources/misc.js @@ -0,0 +1,12 @@ +const { object } = require("./utils") +const Resource = require("./utils/Resource") + +module.exports = new Resource().setSchemas({ + nameSearch: object({ + name: { + type: "string", + description: + "The name to be used when searching - this will be used in a case insensitive starts with match.", + }, + }), +}) diff --git a/packages/server/specs/resources/query.js b/packages/server/specs/resources/query.js new file mode 100644 index 0000000000..c1bbaf0185 --- /dev/null +++ b/packages/server/specs/resources/query.js @@ -0,0 +1,56 @@ +const { object } = require("./utils") +const Resource = require("./utils/Resource") + +const query = { + _id: "query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e", + datasourceId: "datasource_plus_4d8be0c506b9465daf4bf84d890fdab6", + parameters: [], + fields: { + sql: "select * from persons", + }, + queryVerb: "read", + name: "Help", + schema: { + personid: { + name: "personid", + type: "string", + }, + lastname: { + name: "lastname", + type: "string", + }, + firstname: { + name: "firstname", + type: "string", + }, + address: { + name: "address", + type: "string", + }, + city: { + name: "city", + type: "string", + }, + }, + transformer: "return data", + readable: true, +} + +const querySchema = object({}) + +module.exports = new Resource() + .setExamples({ + query: { + value: { + query: query, + }, + }, + queries: { + value: { + queries: [query], + }, + }, + }) + .setSchemas({ + query: querySchema, + }) diff --git a/packages/server/specs/resources/row.js b/packages/server/specs/resources/row.js new file mode 100644 index 0000000000..25e3615d47 --- /dev/null +++ b/packages/server/specs/resources/row.js @@ -0,0 +1,64 @@ +const { object } = require("./utils") +const Resource = require("./utils/Resource") + +const baseRow = { + _id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", + type: "row", + tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", + name: "Mike", + age: 30, +} + +const inputRow = { + ...baseRow, + relationship: ["ro_ta_..."], +} + +const row = { + ...baseRow, + relationship: [ + { + primaryDisplay: "Joe", + _id: "ro_ta_...", + }, + ], +} + +const rowSchema = { + description: "The row to be created/updated, based on the table schema.", + type: "object", + additionalProperties: { + oneOf: [ + { type: "string" }, + { type: "object" }, + { type: "integer" }, + { type: "array" }, + { type: "boolean" }, + ], + }, +} + +module.exports = new Resource() + .setExamples({ + inputRow: { + value: inputRow, + }, + row: { + value: { + row: row, + }, + }, + rows: { + value: { + rows: [row], + hasNextPage: true, + bookmark: 10, + }, + }, + }) + .setSchemas({ + row: rowSchema, + rowOutput: object({ + row: rowSchema, + }), + }) diff --git a/packages/server/specs/schemas.js b/packages/server/specs/resources/table.js similarity index 80% rename from packages/server/specs/schemas.js rename to packages/server/specs/resources/table.js index 59e0c676f0..37412eb23e 100644 --- a/packages/server/specs/schemas.js +++ b/packages/server/specs/resources/table.js @@ -2,19 +2,29 @@ const { FieldTypes, RelationshipTypes, FormulaTypes, -} = require("../src/constants") +} = require("../../src/constants") +const { object } = require("./utils") +const Resource = require("./utils/Resource") -exports.row = { - description: "The row to be created/updated, based on the table schema.", - type: "object", - additionalProperties: { - oneOf: [ - { type: "string" }, - { type: "object" }, - { type: "integer" }, - { type: "array" }, - { type: "boolean" }, - ], +const table = { + _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", + }, }, } @@ -50,7 +60,7 @@ const baseColumnDef = { }, } -exports.table = { +const tableSchema = { description: "The table to be created/updated.", type: "object", properties: { @@ -144,39 +154,22 @@ exports.table = { }, } -function object(props) { - return { - type: "object", - properties: props, - } -} - -exports.query = object({}) - -exports.user = object({}) - -exports.application = object({}) - -exports.applicationOutput = object({ - application: exports.application, -}) - -exports.tableOutput = object({ - table: exports.table, -}) - -exports.userOutput = object({ - user: exports.user, -}) - -exports.rowOutput = object({ - row: exports.row, -}) - -exports.nameSearch = object({ - name: { - type: "string", - description: - "The name to be used when searching - this will be used in a case insensitive starts with match.", - }, -}) +module.exports = new Resource() + .setExamples({ + table: { + value: { + table: table, + }, + }, + tables: { + value: { + tables: [table], + }, + }, + }) + .setSchemas({ + table: tableSchema, + tableOutput: object({ + table: tableSchema, + }), + }) diff --git a/packages/server/specs/resources/user.js b/packages/server/specs/resources/user.js new file mode 100644 index 0000000000..f41bd6d7f3 --- /dev/null +++ b/packages/server/specs/resources/user.js @@ -0,0 +1,50 @@ +const { object } = require("./utils") +const Resource = require("./utils/Resource") + +const user = { + _id: "us_693a73206518477283a8d5ae31103252", + email: "test@test.com", + roles: { + app_957b12f943d348faa61db7e18e088d0f: "BASIC", + }, + builder: { + global: false, + }, + admin: { + global: true, + }, + tenantId: "default", + status: "active", + budibaseAccess: true, + csrfToken: "9c70291d-7137-48f9-9166-99ab5473a3d4", + userId: "us_693a73206518477283a8d5ae31103252", + roleId: "ADMIN", + role: { + _id: "ADMIN", + name: "Admin", + permissionId: "admin", + inherits: "POWER", + }, +} + +const userSchema = object({}) + +module.exports = new Resource() + .setExamples({ + user: { + value: { + user: user, + }, + }, + users: { + value: { + users: [user], + }, + }, + }) + .setSchemas({ + user: userSchema, + userOutput: object({ + user: userSchema, + }), + }) diff --git a/packages/server/specs/resources/utils/Resource.js b/packages/server/specs/resources/utils/Resource.js new file mode 100644 index 0000000000..69ed7001a6 --- /dev/null +++ b/packages/server/specs/resources/utils/Resource.js @@ -0,0 +1,26 @@ +class Resource { + constructor() { + this.examples = {} + this.schemas = {} + } + + setExamples(examples) { + this.examples = examples + return this + } + + setSchemas(schemas) { + this.schemas = schemas + return this + } + + getExamples() { + return this.examples + } + + getSchemas() { + return this.schemas + } +} + +module.exports = Resource diff --git a/packages/server/specs/resources/utils/index.js b/packages/server/specs/resources/utils/index.js new file mode 100644 index 0000000000..d42a582f63 --- /dev/null +++ b/packages/server/specs/resources/utils/index.js @@ -0,0 +1,6 @@ +exports.object = props => { + return { + type: "object", + properties: props, + } +} diff --git a/packages/server/src/api/routes/public/users.js b/packages/server/src/api/routes/public/users.js index a8478e4b6a..0745d65e16 100644 --- a/packages/server/src/api/routes/public/users.js +++ b/packages/server/src/api/routes/public/users.js @@ -42,6 +42,12 @@ router.post("/users/search", controller.search) * - users * parameters: * - $ref: '#/components/parameters/appId' + * requestBody: + * required: true + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/user' * responses: * 200: * description: Returns the created user. @@ -65,6 +71,12 @@ router.post("/users", controller.create) * parameters: * - $ref: '#/components/parameters/userId' * - $ref: '#/components/parameters/appId' + * requestBody: + * required: true + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/user' * responses: * 200: * description: Returns the updated user.