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 swaggerJsdoc = require("swagger-jsdoc")
const { join } = require("path") const { join } = require("path")
const { writeFileSync } = require("fs") const { writeFileSync } = require("fs")
const examples = require("./examples") const { examples, schemas } = require("./resources")
const parameters = require("./parameters") const parameters = require("./parameters")
const security = require("./security") const security = require("./security")
const schemas = require("./schemas")
const VARIABLES = {} const VARIABLES = {}

View File

@ -73,52 +73,82 @@
} }
}, },
"examples": { "examples": {
"table": { "application": {
"value": { "value": {
"table": { "application": {
"_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70", "_id": "app_metadata",
"name": "People", "appId": "app_dev_957b12f943d348faa61db7e18e088d0f",
"schema": { "version": "1.0.58-alpha.0",
"name": { "name": "App name",
"type": "string", "url": "/app-url",
"name": "name" "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": { "builder": {
"type": "number", "global": false
"name": "age"
}, },
"relationship": { "admin": {
"type": "link", "global": true
"name": "relationship", },
"tableId": "ta_...", "tenantId": "default",
"fieldName": "relatedColumn", "status": "active",
"relationshipType": "many-to-many" "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": { "value": {
"tables": [ "applications": [
{ {
"_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70", "_id": "app_metadata",
"name": "People", "appId": "app_dev_957b12f943d348faa61db7e18e088d0f",
"schema": { "version": "1.0.58-alpha.0",
"name": { "name": "App name",
"type": "string", "url": "/app-url",
"name": "name" "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": { "builder": {
"type": "number", "global": false
"name": "age"
}, },
"relationship": { "admin": {
"type": "link", "global": true
"name": "relationship", },
"tableId": "ta_...", "tenantId": "default",
"fieldName": "relatedColumn", "status": "active",
"relationshipType": "many-to-many" "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 "bookmark": 10
} }
}, },
"user": { "table": {
"value": { "value": {
"user": { "table": {
"_id": "us_693a73206518477283a8d5ae31103252", "_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"email": "test@test.com", "name": "People",
"roles": { "schema": {
"app_957b12f943d348faa61db7e18e088d0f": "BASIC" "name": {
}, "type": "string",
"builder": { "name": "name"
"global": false },
}, "age": {
"admin": { "type": "number",
"global": true "name": "age"
}, },
"tenantId": "default", "relationship": {
"status": "active", "type": "link",
"budibaseAccess": true, "name": "relationship",
"csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", "tableId": "ta_...",
"userId": "us_693a73206518477283a8d5ae31103252", "fieldName": "relatedColumn",
"roleId": "ADMIN", "relationshipType": "many-to-many"
"role": { }
"_id": "ADMIN",
"name": "Admin",
"permissionId": "admin",
"inherits": "POWER"
} }
} }
} }
}, },
"users": { "tables": {
"value": { "value": {
"users": [ "tables": [
{ {
"_id": "us_693a73206518477283a8d5ae31103252", "_id": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"email": "test@test.com", "name": "People",
"roles": { "schema": {
"app_957b12f943d348faa61db7e18e088d0f": "BASIC" "name": {
}, "type": "string",
"builder": { "name": "name"
"global": false },
}, "age": {
"admin": { "type": "number",
"global": true "name": "age"
}, },
"tenantId": "default", "relationship": {
"status": "active", "type": "link",
"budibaseAccess": true, "name": "relationship",
"csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4", "tableId": "ta_...",
"userId": "us_693a73206518477283a8d5ae31103252", "fieldName": "relatedColumn",
"roleId": "ADMIN", "relationshipType": "many-to-many"
"role": { }
"_id": "ADMIN",
"name": "Admin",
"permissionId": "admin",
"inherits": "POWER"
} }
} }
] ]
@ -313,19 +335,39 @@
] ]
} }
}, },
"application": { "user": {
"value": { "value": {
"application": { "user": {
"_id": "app_metadata", "_id": "us_693a73206518477283a8d5ae31103252",
"appId": "app_dev_957b12f943d348faa61db7e18e088d0f", "email": "test@test.com",
"version": "1.0.58-alpha.0", "roles": {
"name": "App name", "app_957b12f943d348faa61db7e18e088d0f": "BASIC"
"url": "/app-url", },
"builder": {
"global": false
},
"admin": {
"global": true
},
"tenantId": "default", "tenantId": "default",
"updatedAt": "2022-02-22T13:00:54.035Z", "status": "active",
"createdAt": "2022-02-11T18:02:26.961Z", "budibaseAccess": true,
"status": "development", "csrfToken": "9c70291d-7137-48f9-9166-99ab5473a3d4",
"lockedBy": { "userId": "us_693a73206518477283a8d5ae31103252",
"roleId": "ADMIN",
"role": {
"_id": "ADMIN",
"name": "Admin",
"permissionId": "admin",
"inherits": "POWER"
}
}
}
},
"users": {
"value": {
"users": [
{
"_id": "us_693a73206518477283a8d5ae31103252", "_id": "us_693a73206518477283a8d5ae31103252",
"email": "test@test.com", "email": "test@test.com",
"roles": { "roles": {
@ -350,48 +392,6 @@
"inherits": "POWER" "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": { "schemas": {
"application": {
"type": "object",
"properties": {}
},
"applicationOutput": {
"type": "object",
"properties": {
"application": {
"type": "object",
"properties": {}
}
}
},
"row": { "row": {
"description": "The row to be created/updated, based on the table schema.", "description": "The row to be created/updated, based on the table schema.",
"type": "object", "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": { "table": {
"description": "The table to be created/updated.", "description": "The table to be created/updated.",
"type": "object", "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": { "tableOutput": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -838,6 +858,14 @@
} }
} }
}, },
"query": {
"type": "object",
"properties": {}
},
"user": {
"type": "object",
"properties": {}
},
"userOutput": { "userOutput": {
"type": "object", "type": "object",
"properties": { "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": { "nameSearch": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1750,6 +1750,16 @@
"$ref": "#/components/parameters/appId" "$ref": "#/components/parameters/appId"
} }
], ],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/user"
}
}
}
},
"responses": { "responses": {
"200": { "200": {
"description": "Returns the created user.", "description": "Returns the created user.",
@ -1783,6 +1793,16 @@
"$ref": "#/components/parameters/appId" "$ref": "#/components/parameters/appId"
} }
], ],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/user"
}
}
}
},
"responses": { "responses": {
"200": { "200": {
"description": "Returns the updated user.", "description": "Returns the updated user.",

View File

@ -53,175 +53,6 @@ components:
schema: schema:
type: string type: string
examples: 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: application:
value: value:
application: application:
@ -286,6 +117,175 @@ components:
name: Admin name: Admin
permissionId: admin permissionId: admin
inherits: POWER 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: securitySchemes:
ApiKeyAuth: ApiKeyAuth:
type: apiKey type: apiKey
@ -294,6 +294,15 @@ components:
description: Your individual API key, this will provide access based on the description: Your individual API key, this will provide access based on the
configured RBAC settings of your user. configured RBAC settings of your user.
schemas: schemas:
application:
type: object
properties: {}
applicationOutput:
type: object
properties:
application:
type: object
properties: {}
row: row:
description: The row to be created/updated, based on the table schema. description: The row to be created/updated, based on the table schema.
type: object type: object
@ -304,6 +313,19 @@ components:
- type: integer - type: integer
- type: array - type: array
- type: boolean - 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: table:
description: The table to be created/updated. description: The table to be created/updated.
type: object type: object
@ -455,21 +477,6 @@ components:
autocolumn: autocolumn:
type: boolean type: boolean
description: Defines whether the column is automatically generated. 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: tableOutput:
type: object type: object
properties: properties:
@ -626,25 +633,18 @@ components:
autocolumn: autocolumn:
type: boolean type: boolean
description: Defines whether the column is automatically generated. description: Defines whether the column is automatically generated.
query:
type: object
properties: {}
user:
type: object
properties: {}
userOutput: userOutput:
type: object type: object
properties: properties:
user: user:
type: object type: object
properties: {} 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: nameSearch:
type: object type: object
properties: properties:
@ -1174,6 +1174,12 @@ paths:
- users - users
parameters: parameters:
- $ref: "#/components/parameters/appId" - $ref: "#/components/parameters/appId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/user"
responses: responses:
"200": "200":
description: Returns the created user. description: Returns the created user.
@ -1192,6 +1198,12 @@ paths:
parameters: parameters:
- $ref: "#/components/parameters/userId" - $ref: "#/components/parameters/userId"
- $ref: "#/components/parameters/appId" - $ref: "#/components/parameters/appId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/user"
responses: responses:
"200": "200":
description: Returns the updated user. 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, FieldTypes,
RelationshipTypes, RelationshipTypes,
FormulaTypes, FormulaTypes,
} = require("../src/constants") } = require("../../src/constants")
const { object } = require("./utils")
const Resource = require("./utils/Resource")
exports.row = { const table = {
description: "The row to be created/updated, based on the table schema.", _id: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
type: "object", name: "People",
additionalProperties: { schema: {
oneOf: [ name: {
{ type: "string" }, type: "string",
{ type: "object" }, name: "name",
{ type: "integer" }, },
{ type: "array" }, age: {
{ type: "boolean" }, 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.", description: "The table to be created/updated.",
type: "object", type: "object",
properties: { properties: {
@ -144,39 +154,22 @@ exports.table = {
}, },
} }
function object(props) { module.exports = new Resource()
return { .setExamples({
type: "object", table: {
properties: props, value: {
} table: table,
} },
},
exports.query = object({}) tables: {
value: {
exports.user = object({}) tables: [table],
},
exports.application = object({}) },
})
exports.applicationOutput = object({ .setSchemas({
application: exports.application, table: tableSchema,
}) tableOutput: object({
table: tableSchema,
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.",
},
})

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 * - users
* parameters: * parameters:
* - $ref: '#/components/parameters/appId' * - $ref: '#/components/parameters/appId'
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/user'
* responses: * responses:
* 200: * 200:
* description: Returns the created user. * description: Returns the created user.
@ -65,6 +71,12 @@ router.post("/users", controller.create)
* parameters: * parameters:
* - $ref: '#/components/parameters/userId' * - $ref: '#/components/parameters/userId'
* - $ref: '#/components/parameters/appId' * - $ref: '#/components/parameters/appId'
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/user'
* responses: * responses:
* 200: * 200:
* description: Returns the updated user. * description: Returns the updated user.