Adding in row schema for create/update, making sure all existing endpoints have appId specified.

This commit is contained in:
mike12345567 2022-02-18 17:44:08 +00:00
parent edcb138366
commit bb917467ff
10 changed files with 578 additions and 136 deletions

View File

@ -1,9 +1,18 @@
const row = {
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",
@ -12,30 +21,40 @@ const row = {
],
}
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",
},
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",
},
},
}
exports.table = {
value: table,
}
exports.tables = {
value: [table],
}
exports.inputRow = {
value: inputRow,
}
exports.row = {
value: row,
}

View File

@ -4,6 +4,7 @@ const { writeFileSync } = require("fs")
const examples = require("./examples")
const parameters = require("./parameters")
const security = require("./security")
const schemas = require("./schemas")
const VARIABLES = {}
@ -35,6 +36,9 @@ const options = {
securitySchemes: {
...security,
},
schemas: {
...schemas,
},
},
security: [
{

View File

@ -34,6 +34,15 @@
"schema": {
"type": "string"
}
},
"appId": {
"in": "header",
"name": "appId",
"required": true,
"description": "The ID of the app which this request is targeting.",
"schema": {
"type": "string"
}
}
},
"examples": {
@ -60,6 +69,43 @@
}
}
},
"tables": {
"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"
}
}
}
]
},
"inputRow": {
"value": {
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
"type": "row",
"tableId": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
"name": "Mike",
"age": 30,
"relationship": [
"ro_ta_..."
]
}
},
"row": {
"value": {
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
@ -104,6 +150,31 @@
"name": "x-budibase-api-key",
"description": "Your individual API key, this will provide access based on the configured RBAC settings of your user."
}
},
"schemas": {
"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"
}
]
}
}
}
},
"security": [
@ -121,6 +192,9 @@
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"requestBody": {
@ -151,7 +225,13 @@
},
"range": {
"type": "object",
"description": "Searches within a range, the format of this must be columnName -> [low, high]."
"description": "Searches within a range, the format of this must be columnName -> [low, high].",
"example": {
"columnName1": [
10,
20
]
}
},
"equal": {
"type": "object",
@ -163,7 +243,10 @@
},
"empty": {
"type": "object",
"description": "Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value."
"description": "Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.",
"example": {
"columnName1": ""
}
},
"notEmpty": {
"type": "object",
@ -255,11 +338,11 @@
"description": "If pagination in use, this will determine if there is another page to fetch.",
"type": "boolean"
}
},
"examples": {
"search": [
"#/components/examples/search"
]
}
},
"examples": {
"search": {
"$ref": "#/components/examples/search"
}
}
}
@ -277,6 +360,9 @@
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"requestBody": {
@ -284,29 +370,11 @@
"content": {
"application/json": {
"schema": {
"description": "The contents of the row which is to be created, the keys of",
"type": "object",
"example": {
"$ref": "#/components/examples/row"
},
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "integer"
},
{
"type": "array"
},
{
"type": "boolean"
}
]
"$ref": "#/components/schemas/row"
},
"examples": {
"row": {
"$ref": "#/components/examples/inputRow"
}
}
}
@ -343,8 +411,26 @@
},
{
"$ref": "#/components/parameters/rowId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/row"
},
"examples": {
"row": {
"$ref": "#/components/examples/inputRow"
}
}
}
}
},
"responses": {
"200": {
"description": "Returns the created row, including the ID which has been generated for it.",
@ -374,6 +460,9 @@
},
{
"$ref": "#/components/parameters/rowId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"responses": {
@ -405,6 +494,9 @@
},
{
"$ref": "#/components/parameters/rowId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"responses": {
@ -426,22 +518,158 @@
}
}
},
"/tables/search": {
"post": {
"summary": "Search internal and external tables based on their name.",
"parameters": [
{
"$ref": "#/components/parameters/appId"
}
],
"tags": [
"tables"
],
"requestBody": null,
"responses": {
"200": {
"description": "Returns the found tables, based on the search parameters.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object"
}
},
"examples": {
"tables": {
"$ref": "#/components/examples/tables"
}
}
}
}
}
}
}
},
"/tables": {
"post": {
"summary": "Create a new table",
"summary": "Create a new table.",
"parameters": [
{
"$ref": "#/components/parameters/appId"
}
],
"tags": [
"tables"
],
"responses": {
"200": {
"description": "Returns the created table, including the ID which has been generated for it.",
"description": "Returns the created table, including the ID which has been generated for it. This can be internal or external data sources.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"row": {
"table": {
"$ref": "#/components/examples/table"
}
}
}
}
}
}
},
"get": {
"summary": "Get all the tables, internal and external within an app.",
"tags": [
"tables"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"responses": {
"200": {
"description": "Returns all of the tables which were found.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"table": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
}
},
"/tables/:tableId": {
"put": {
"summary": "Update the specified table. This can be for internal or external tables.",
"tags": [
"tables"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"responses": {
"200": {
"description": "Returns the updated table.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"table": {
"$ref": "#/components/examples/row"
}
}
}
}
}
}
}
},
"/tables/{tableId}": {
"delete": {
"summary": "Delete a single table and all of its data.",
"tags": [
"tables"
],
"parameters": [
{
"$ref": "#/components/parameters/tableId"
},
{
"$ref": "#/components/parameters/appId"
}
],
"responses": {
"200": {
"description": "Returns the deleted table.",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"table": {
"$ref": "#/components/examples/table"
}
}

View File

@ -24,6 +24,13 @@ components:
description: The ID of the row which this request is targeting.
schema:
type: string
appId:
in: header
name: appId
required: true
description: The ID of the app which this request is targeting.
schema:
type: string
examples:
table:
value:
@ -42,6 +49,32 @@ components:
tableId: ta_...
fieldName: relatedColumn
relationshipType: many-to-many
tables:
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
inputRow:
value:
_id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
type: row
tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70
name: Mike
age: 30
relationship:
- ro_ta_...
row:
value:
_id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
@ -72,6 +105,17 @@ components:
name: x-budibase-api-key
description: Your individual API key, this will provide access based on the
configured RBAC settings of your user.
schemas:
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
security:
- ApiKeyAuth: []
paths:
@ -82,6 +126,7 @@ paths:
- rows
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/appId"
requestBody:
required: true
content:
@ -109,6 +154,10 @@ paths:
type: object
description: Searches within a range, the format of this must be columnName ->
[low, high].
example:
columnName1:
- 10
- 20
equal:
type: object
description: Searches for rows that have a column value that is exactly the
@ -122,6 +171,8 @@ paths:
description: Searches for rows which do not contain the specified column. The
object should simply contain keys of the column names,
these can map to any value.
example:
columnName1: ""
notEmpty:
type: object
description: Searches for rows which have the specified column.
@ -188,9 +239,9 @@ paths:
description: If pagination in use, this will determine if there is another page
to fetch.
type: boolean
examples:
search:
- "#/components/examples/search"
examples:
search:
$ref: "#/components/examples/search"
"/tables/{tableId}/rows":
post:
summary: Creates a new row within a specified table.
@ -198,22 +249,16 @@ paths:
- rows
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/appId"
requestBody:
required: true
content:
application/json:
schema:
description: The contents of the row which is to be created, the keys of
type: object
example:
$ref: "#/components/examples/row"
additionalProperties:
oneOf:
- type: string
- type: object
- type: integer
- type: array
- type: boolean
$ref: "#/components/schemas/row"
examples:
row:
$ref: "#/components/examples/inputRow"
responses:
"200":
description: Returns the created row, including the ID which has been generated
@ -234,6 +279,16 @@ paths:
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
- $ref: "#/components/parameters/appId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/row"
examples:
row:
$ref: "#/components/examples/inputRow"
responses:
"200":
description: Returns the created row, including the ID which has been generated
@ -252,6 +307,7 @@ paths:
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
- $ref: "#/components/parameters/appId"
responses:
"200":
description: Returns the deleted row, including the ID which has been generated
@ -270,6 +326,7 @@ paths:
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/rowId"
- $ref: "#/components/parameters/appId"
responses:
"200":
description: Returns the retrieved row.
@ -280,20 +337,95 @@ paths:
examples:
row:
$ref: "#/components/examples/row"
/tables/search:
post:
summary: Search internal and external tables based on their name.
parameters:
- $ref: "#/components/parameters/appId"
tags:
- tables
requestBody: null
responses:
"200":
description: Returns the found tables, based on the search parameters.
content:
application/json:
schema:
type: array
items:
type: object
examples:
tables:
$ref: "#/components/examples/tables"
/tables:
post:
summary: Create a new table
summary: Create a new table.
parameters:
- $ref: "#/components/parameters/appId"
tags:
- tables
responses:
"200":
description: Returns the created table, including the ID which has been
generated for it.
generated for it. This can be internal or external data sources.
content:
application/json:
schema:
type: object
examples:
row:
table:
$ref: "#/components/examples/table"
get:
summary: Get all the tables, internal and external within an app.
tags:
- tables
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/appId"
responses:
"200":
description: Returns all of the tables which were found.
content:
application/json:
schema:
type: object
examples:
table:
$ref: "#/components/examples/row"
/tables/:tableId:
put:
summary: Update the specified table. This can be for internal or external tables.
tags:
- tables
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/appId"
responses:
"200":
description: Returns the updated table.
content:
application/json:
schema:
type: object
examples:
table:
$ref: "#/components/examples/row"
"/tables/{tableId}":
delete:
summary: Delete a single table and all of its data.
tags:
- tables
parameters:
- $ref: "#/components/parameters/tableId"
- $ref: "#/components/parameters/appId"
responses:
"200":
description: Returns the deleted table.
content:
application/json:
schema:
type: object
examples:
table:
$ref: "#/components/examples/table"
tags: []

View File

@ -17,3 +17,13 @@ exports.rowId = {
type: "string",
},
}
exports.appId = {
in: "header",
name: "appId",
required: true,
description: "The ID of the app which this request is targeting.",
schema: {
type: "string",
},
}

View File

@ -0,0 +1,13 @@
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" },
],
},
}

View File

@ -1,17 +1,35 @@
// makes sure that the user doesn't need to pass in the type, tableId or _id params for
// the call to be correct
function fixRow(row, params) {
if (!params || !row) {
return row
}
if (params.rowId) {
row._id = params.rowId
}
if (params.tableId) {
row.tableId = params.tableId
}
if (!row.type) {
row.type = "row"
}
return row
}
exports.search = () => {
}
exports.create = () => {
ctx.request.body = fixRow(ctx.request.body, ctx.params)
}
exports.singleRead = () => {
}
exports.update = () => {
exports.update = async ctx => {
ctx.request.body = fixRow(ctx.request.body, ctx.params)
}
exports.delete = () => {

View File

@ -1,12 +1,12 @@
exports.search = () => {
}
exports.create = () => {
}
exports.getAllTables = () => {
}
exports.getSingleTable = () => {
exports.singleRead = () => {
}

View File

@ -12,6 +12,7 @@ const router = Router()
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/appId'
* requestBody:
* required: true
* content:
@ -40,6 +41,8 @@ const router = Router()
* type: object
* description: Searches within a range, the format of this must be
* columnName -> [low, high].
* example:
* columnName1: [10, 20]
* equal:
* type: object
* description: Searches for rows that have a column value that is
@ -53,6 +56,8 @@ const router = Router()
* description: Searches for rows which do not contain the specified column.
* The object should simply contain keys of the column names, these
* can map to any value.
* example:
* columnName1: ""
* notEmpty:
* type: object
* description: Searches for rows which have the specified column.
@ -110,9 +115,9 @@ const router = Router()
* hasNextPage:
* description: If pagination in use, this will determine if there is another page to fetch.
* type: boolean
* examples:
* search:
* - '#/components/examples/search'
* examples:
* search:
* $ref: '#/components/examples/search'
*/
router.post("/tables/:tableId/rows/search", controller.search)
@ -125,22 +130,16 @@ router.post("/tables/:tableId/rows/search", controller.search)
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/appId'
* requestBody:
* required: true
* content:
* application/json:
* schema:
* description: The contents of the row which is to be created, the keys of
* type: object
* example:
* $ref: '#/components/examples/row'
* additionalProperties:
* oneOf:
* - type: string
* - type: object
* - type: integer
* - type: array
* - type: boolean
* $ref: '#/components/schemas/row'
* examples:
* row:
* $ref: '#/components/examples/inputRow'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
@ -165,6 +164,16 @@ router.post("/tables/:tableId/rows", controller.create)
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/row'
* examples:
* row:
* $ref: '#/components/examples/inputRow'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
@ -188,6 +197,7 @@ router.put("/tables/:tableId/rows/:rowId", controller.update)
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* responses:
* 200:
* description: Returns the deleted row, including the ID which has been generated for it.
@ -211,6 +221,7 @@ router.delete("/tables/:tableId/rows/:rowId", controller.delete)
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* responses:
* 200:
* description: Returns the retrieved row.

View File

@ -2,22 +2,52 @@ const Router = require("@koa/router")
const controller = require("../../controllers/public/tables")
const router = Router()
/**
* @openapi
* /tables/search:
* post:
* summary: Search internal and external tables based on their name.
* parameters:
* - $ref: '#/components/parameters/appId'
* tags:
* - tables
* requestBody:
*
* responses:
* 200:
* description: Returns the found tables, based on the search parameters.
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* examples:
* tables:
* $ref: '#/components/examples/tables'
*/
router.post("/tables/search", controller.search)
/**
* @openapi
* /tables:
* post:
* summary: Create a new table
* summary: Create a new table.
* parameters:
* - $ref: '#/components/parameters/appId'
* tags:
* - tables
* responses:
* 200:
* description: Returns the created table, including the ID which has been generated for it.
* description: Returns the created table, including the ID which has been generated for it. This can be
* internal or external data sources.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* table:
* $ref: '#/components/examples/table'
*/
router.post("/tables", controller.create)
@ -26,21 +56,21 @@ router.post("/tables", controller.create)
* @openapi
* /tables/:tableId:
* put:
* summary: Update a single row within a specified table.
* summary: Update the specified table. This can be for internal or external tables.
* tags:
* - tables
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* description: Returns the updated table.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* table:
* $ref: '#/components/examples/row'
*/
router.put("/tables/:tableId", controller.update)
@ -49,68 +79,45 @@ router.put("/tables/:tableId", controller.update)
* @openapi
* /tables:
* get:
* summary: Update a single row within a specified table.
* summary: Get all the tables, internal and external within an app.
* tags:
* - tables
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* description: Returns all of the tables which were found.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* table:
* $ref: '#/components/examples/row'
*/
router.get("/tables", controller.getAllTables)
router.get("/tables", controller.singleRead)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* put:
* summary: Update a single row within a specified table.
* /tables/{tableId}:
* delete:
* summary: Delete a single table and all of its data.
* tags:
* - rows
* - tables
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* - $ref: '#/components/parameters/appId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* description: Returns the deleted table.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
*/
router.get("/tables/:tableId", controller.getSingleTable)
/**
* @openapi
* /tables/{tableId}/rows/{rowId}:
* put:
* summary: Update a single row within a specified table.
* tags:
* - rows
* parameters:
* - $ref: '#/components/parameters/tableId'
* - $ref: '#/components/parameters/rowId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
* examples:
* row:
* $ref: '#/components/examples/row'
* table:
* $ref: '#/components/examples/table'
*/
router.delete("/tables/:tableId", controller.delete)