Adding a structure for breaking up examples and parameters.

This commit is contained in:
mike12345567 2022-02-17 19:55:37 +00:00
parent 6a09fdc3e5
commit 51b4d42492
6 changed files with 131 additions and 62 deletions

View File

@ -0,0 +1,39 @@
exports.table = {
value: {
_id: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
name: "People",
schema: {
name: {
type: "string",
name: "name",
},
age: {
type: "number",
name: "age",
},
relationship: {
type: "link",
name: "relationship",
tableId: "ta_...",
fieldName: "relatedColumn",
relationshipType: "many-to-many",
},
},
},
}
exports.row = {
value: {
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
type: "row",
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
name: "Mike",
age: 30,
relationship: [
{
primaryDisplay: "Joe",
_id: "ro_ta_...",
},
],
},
}

View File

@ -1,6 +1,8 @@
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 { row, table } = require("./examples")
const { tableId } = require("./parameters")
const VARIABLES = {} const VARIABLES = {}
@ -23,45 +25,12 @@ const options = {
}, },
], ],
components: { components: {
parameters: {
tableId: tableId,
},
examples: { examples: {
row: { row: row,
value: { table: table,
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
type: "row",
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
name: "Mike",
age: 30,
relationship: [
{
primaryDisplay: "Joe",
_id: "ro_ta_...",
},
],
},
},
table: {
value: {
_id: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
name: "People",
schema: {
name: {
type: "string",
name: "name",
},
age: {
type: "number",
name: "age",
},
relationship: {
type: "link",
name: "relationship",
tableId: "ta_...",
fieldName: "relatedColumn",
relationshipType: "many-to-many",
},
},
},
},
}, },
}, },
}, },

View File

@ -16,6 +16,17 @@
} }
], ],
"components": { "components": {
"parameters": {
"tableId": {
"in": "path",
"name": "tableId",
"required": true,
"description": "The ID of the table which contains the rows which are being searched for.",
"schema": {
"type": "string"
}
}
},
"examples": { "examples": {
"row": { "row": {
"value": { "value": {
@ -58,18 +69,12 @@
} }
}, },
"paths": { "paths": {
"/row/{tableId}/search": { "/tables/{tableId}/rows/search": {
"post": { "post": {
"summary": "Allows searching for rows within a table.", "summary": "Allows searching for rows within a table.",
"parameters": [ "parameters": [
{ {
"in": "path", "$ref": "#/components/parameters/tableId"
"name": "tableId",
"required": true,
"description": "The ID of the table which contains the rows which are being searched for.",
"schema": {
"type": "string"
}
} }
], ],
"requestBody": { "requestBody": {
@ -214,6 +219,28 @@
} }
} }
} }
},
"/tables/{tableId}/rows": {
"post": {
"summary": "Allows creating a row within a specified table.",
"parameters": [
{
"$ref": "#/components/parameters/tableId"
}
],
"responses": {
"200": {
"description": "Returns the created row, including the ID which has been generated for it.",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
} }
}, },
"tags": [] "tags": []

View File

@ -9,6 +9,14 @@ servers:
- url: "{protocol}://{hostname}:10000/api/public/v1" - url: "{protocol}://{hostname}:10000/api/public/v1"
description: Budibase self hosted API description: Budibase self hosted API
components: components:
parameters:
tableId:
in: path
name: tableId
required: true
description: The ID of the table which contains the rows which are being searched for.
schema:
type: string
examples: examples:
row: row:
value: value:
@ -38,17 +46,11 @@ components:
fieldName: relatedColumn fieldName: relatedColumn
relationshipType: many-to-many relationshipType: many-to-many
paths: paths:
"/row/{tableId}/search": "/tables/{tableId}/rows/search":
post: post:
summary: Allows searching for rows within a table. summary: Allows searching for rows within a table.
parameters: parameters:
- in: path - $ref: "#/components/parameters/tableId"
name: tableId
required: true
description: The ID of the table which contains the rows which are being
searched for.
schema:
type: string
requestBody: requestBody:
required: true required: true
content: content:
@ -157,4 +159,17 @@ paths:
description: If pagination in use, this will determine if there is another page description: If pagination in use, this will determine if there is another page
to fetch. to fetch.
type: boolean type: boolean
"/tables/{tableId}/rows":
post:
summary: Allows creating a row within a specified table.
parameters:
- $ref: "#/components/parameters/tableId"
responses:
"200":
description: Returns the created row, including the ID which has been generated
for it.
content:
application/json:
schema:
type: object
tags: [] tags: []

View File

@ -0,0 +1,10 @@
exports.tableId = {
in: "path",
name: "tableId",
required: true,
description:
"The ID of the table which contains the rows which are being searched for.",
schema: {
type: "string",
},
}

View File

@ -5,17 +5,11 @@ const router = Router()
/** /**
* @openapi * @openapi
* /row/{tableId}/search: * /tables/{tableId}/rows/search:
* post: * post:
* summary: Allows searching for rows within a table. * summary: Allows searching for rows within a table.
* parameters: * parameters:
* - in: path * - $ref: '#/components/parameters/tableId'
* name: tableId
* required: true
* description: The ID of the table which contains the rows
* which are being searched for.
* schema:
* type: string
* requestBody: * requestBody:
* required: true * required: true
* content: * content:
@ -119,6 +113,21 @@ const router = Router()
*/ */
router.post("/tables/:tableId/rows/search", controller.search) router.post("/tables/:tableId/rows/search", controller.search)
/**
* @openapi
* /tables/{tableId}/rows:
* post:
* summary: Allows creating a row within a specified table.
* parameters:
* - $ref: '#/components/parameters/tableId'
* responses:
* 200:
* description: Returns the created row, including the ID which has been generated for it.
* content:
* application/json:
* schema:
* type: object
*/
router.post("/tables/:tableId/rows", controller.create) router.post("/tables/:tableId/rows", controller.create)
router.put("/tables/:tableId/rows/:rowId", controller.update) router.put("/tables/:tableId/rows/:rowId", controller.update)