1
0
Fork 0
mirror of synced 2024-07-05 22:40:39 +12:00

Refactoring resource system, so that examples and schemas have individual files rather than all being lumped into one.

This commit is contained in:
mike12345567 2022-02-22 15:06:08 +00:00
parent d08c3bd6b5
commit 948c520a6a
14 changed files with 744 additions and 616 deletions

View file

@ -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],
},
}

View file

@ -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 = {}

View file

@ -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.",

View file

@ -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.

View file

@ -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,
}),
})

View file

@ -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(),
}

View file

@ -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.",
},
}),
})

View file

@ -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,
})

View file

@ -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,
}),
})

View file

@ -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,
}),
})

View file

@ -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,
}),
})

View file

@ -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

View file

@ -0,0 +1,6 @@
exports.object = props => {
return {
type: "object",
properties: props,
}
}

View file

@ -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.