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 { join } = require("path")
const { writeFileSync } = require("fs")
const { row, table } = require("./examples")
const { tableId } = require("./parameters")
const VARIABLES = {}
@ -23,45 +25,12 @@ const options = {
},
],
components: {
parameters: {
tableId: tableId,
},
examples: {
row: {
value: {
_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",
},
},
},
},
row: row,
table: table,
},
},
},

View File

@ -16,6 +16,17 @@
}
],
"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": {
"row": {
"value": {
@ -58,18 +69,12 @@
}
},
"paths": {
"/row/{tableId}/search": {
"/tables/{tableId}/rows/search": {
"post": {
"summary": "Allows searching for rows within a table.",
"parameters": [
{
"in": "path",
"name": "tableId",
"required": true,
"description": "The ID of the table which contains the rows which are being searched for.",
"schema": {
"type": "string"
}
"$ref": "#/components/parameters/tableId"
}
],
"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": []

View File

@ -9,6 +9,14 @@ servers:
- url: "{protocol}://{hostname}:10000/api/public/v1"
description: Budibase self hosted API
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:
row:
value:
@ -38,17 +46,11 @@ components:
fieldName: relatedColumn
relationshipType: many-to-many
paths:
"/row/{tableId}/search":
"/tables/{tableId}/rows/search":
post:
summary: Allows searching for rows within a table.
parameters:
- in: path
name: tableId
required: true
description: The ID of the table which contains the rows which are being
searched for.
schema:
type: string
- $ref: "#/components/parameters/tableId"
requestBody:
required: true
content:
@ -157,4 +159,17 @@ paths:
description: If pagination in use, this will determine if there is another page
to fetch.
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: []

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
* /row/{tableId}/search:
* /tables/{tableId}/rows/search:
* post:
* summary: Allows searching for rows within a table.
* parameters:
* - in: path
* name: tableId
* required: true
* description: The ID of the table which contains the rows
* which are being searched for.
* schema:
* type: string
* - $ref: '#/components/parameters/tableId'
* requestBody:
* required: true
* content:
@ -119,6 +113,21 @@ const router = Router()
*/
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.put("/tables/:tableId/rows/:rowId", controller.update)