Browse Source

feat: path correction and swagger

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5901/head
Pranav C 2 years ago
parent
commit
a1f0884eff
  1. 239
      packages/nocodb-sdk/src/lib/Api.ts
  2. 14
      packages/nocodb/src/controllers/data-table.controller.ts
  3. 449
      packages/nocodb/src/schema/swagger.json

239
packages/nocodb-sdk/src/lib/Api.ts

@ -7465,6 +7465,245 @@ export class Api<
format: 'json',
...params,
}),
/**
* @description List all table view rows
*
* @tags DB Table Row
* @name TableRowList
* @summary List Table View Rows
* @request GET:/api/v1/base/{projectId}/tables/{tableId}
* @response `200` `{
\** List of table view rows *\
list: (object)[],
\** Paginated Info *\
pageInfo: PaginatedType,
}` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
tableRowList: (
projectId: string,
tableId: string,
query: {
viewId: string;
fields?: any[];
sort?: any[];
where?: string;
/** Query params for nested data */
nested?: any;
offset?: number;
},
params: RequestParams = {}
) =>
this.request<
{
/** List of table view rows */
list: object[];
/** Paginated Info */
pageInfo: PaginatedType;
},
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/base/${projectId}/tables/${tableId}`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* @description Create a new row in the given Table View
*
* @tags DB Table Row
* @name TableRowCreate
* @summary Create Table View Row
* @request POST:/api/v1/base/{projectId}/tables/{tableId}
* @response `200` `object` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
tableRowCreate: (
projectId: string,
tableId: string,
query: {
viewId: string;
},
data: object,
params: RequestParams = {}
) =>
this.request<
object,
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/base/${projectId}/tables/${tableId}`,
method: 'POST',
query: query,
body: data,
type: ContentType.Json,
format: 'json',
...params,
}),
/**
* @description Count how many rows in the given Table View
*
* @tags DB Table Row
* @name TableRowCount
* @summary Count Table View Rows
* @request GET:/api/v1/base/{projectId}/tables/{tableId}/count
* @response `200` `{
count?: number,
}` OK
*/
tableRowCount: (
projectId: string,
tableId: string,
query: {
viewId: string;
where?: string;
/** Query params for nested data */
nested?: any;
},
params: RequestParams = {}
) =>
this.request<
{
count?: number;
},
any
>({
path: `/api/v1/base/${projectId}/tables/${tableId}/count`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* @description Get the target Table View Row
*
* @tags DB Table Row
* @name DbViewRowRead
* @summary Get Table View Row
* @request GET:/api/v1/db/tables/{tableId}/rows/{rowId}
* @response `200` `object` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
dbViewRowRead: (
tableId: string,
rowId: any,
query: {
viewId: string;
},
params: RequestParams = {}
) =>
this.request<
object,
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/db/tables/${tableId}/rows/${rowId}`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* @description Update the target Table View Row
*
* @tags DB Table Row
* @name TableRowUpdate
* @summary Update Table View Row
* @request PATCH:/api/v1/db/tables/{tableId}/rows/{rowId}
* @response `200` `object` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
tableRowUpdate: (
tableId: string,
rowId: any,
query: {
viewId: string;
},
data: object,
params: RequestParams = {}
) =>
this.request<
object,
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/db/tables/${tableId}/rows/${rowId}`,
method: 'PATCH',
query: query,
body: data,
type: ContentType.Json,
format: 'json',
...params,
}),
/**
* @description Delete the target Table View Row
*
* @tags DB Table Row
* @name TableRowDelete
* @summary Delete Table View Row
* @request DELETE:/api/v1/db/tables/{tableId}/rows/{rowId}
* @response `200` `number` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
tableRowDelete: (
tableId: string,
rowId: any,
query: {
viewId: string;
},
params: RequestParams = {}
) =>
this.request<
number,
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/db/tables/${tableId}/rows/${rowId}`,
method: 'DELETE',
query: query,
format: 'json',
...params,
}),
};
dbViewRow = {
/**

14
packages/nocodb/src/controllers/data-table.controller.ts

@ -27,7 +27,7 @@ export class DataTableController {
constructor(private readonly dataTableService: DataTableService) {}
// todo: Handle the error case where view doesnt belong to model
@Get('/api/v1/db/:projectId/tables/:modelId')
@Get('/api/v1/base/:projectId/tables/:modelId')
@Acl('dataList')
async dataList(
@Request() req,
@ -48,7 +48,7 @@ export class DataTableController {
res.json(responseData);
}
@Get(['/api/v1/db/:projectId/tables/:modelId/count'])
@Get(['/api/v1/base/:projectId/tables/:modelId/count'])
@Acl('dataCount')
async dataCount(
@Request() req,
@ -67,7 +67,7 @@ export class DataTableController {
res.json(countResult);
}
@Post(['/api/v1/db/:projectId/tables/:modelId'])
@Post(['/api/v1/base/:projectId/tables/:modelId'])
@HttpCode(200)
@Acl('dataInsert')
async dataInsert(
@ -86,17 +86,15 @@ export class DataTableController {
});
}
@Patch(['/api/v1/db/:projectId/tables/:modelId/:rowId'])
@Patch(['/api/v1/db/tables/:modelId/rows/:rowId'])
@Acl('dataUpdate')
async dataUpdate(
@Request() req,
@Param('projectId') projectId: string,
@Param('modelId') modelId: string,
@Query('viewId') viewId: string,
@Param('rowId') rowId: string,
) {
return await this.dataTableService.dataUpdate({
projectId: projectId,
modelId: modelId,
body: req.body,
cookie: req,
@ -105,7 +103,7 @@ export class DataTableController {
});
}
@Delete(['/api/v1/db/:projectId/tables/:modelId/:rowId'])
@Delete(['/api/v1/db/tables/:modelId/rows/:rowId'])
@Acl('dataDelete')
async dataDelete(
@Request() req,
@ -123,7 +121,7 @@ export class DataTableController {
});
}
@Get(['/api/v1/db/:projectId/tables/:modelId/:rowId'])
@Get(['/api/v1/db/tables/:modelId/rows/:rowId'])
@Acl('dataRead')
async dataRead(
@Request() req,

449
packages/nocodb/src/schema/swagger.json

@ -13963,6 +13963,455 @@
}
]
}
},
"/api/v1/base/{projectId}/tables/{tableId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "projectId",
"in": "path",
"required": true,
"description": "Project Id"
},
{
"schema": {
"type": "string"
},
"name": "tableId",
"in": "path",
"required": true,
"description": "Table Id"
},
{
"schema": {
"type": "string"
},
"name": "viewId",
"in": "query",
"required": true
}
],
"get": {
"summary": "List Table View Rows",
"operationId": "table-row-list",
"description": "List all table view rows",
"tags": ["DB Table Row"],
"parameters": [
{
"schema": {
"type": "array"
},
"in": "query",
"name": "fields"
},
{
"schema": {
"type": "array"
},
"in": "query",
"name": "sort"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {},
"in": "query",
"name": "nested",
"description": "Query params for nested data"
},
{
"schema": {
"type": "number"
},
"in": "query",
"name": "offset"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"list": {
"type": "array",
"x-stoplight": {
"id": "okd8utzm9xqet"
},
"description": "List of table view rows",
"items": {
"x-stoplight": {
"id": "j758lsjv53o4q"
},
"type": "object"
}
},
"pageInfo": {
"$ref": "#/components/schemas/Paginated",
"x-stoplight": {
"id": "hylgqzgm8yhye"
},
"description": "Paginated Info"
}
},
"required": ["list", "pageInfo"]
},
"examples": {
"Example 1": {
"value": {
"list": [
{
"Id": 1,
"Title": "baz",
"SingleSelect": null,
"Sheet-1 List": [
{
"Id": 1,
"Title": "baz"
}
],
"LTAR": [
{
"Id": 1,
"Title": "baz"
}
]
},
{
"Id": 2,
"Title": "foo",
"SingleSelect": "a",
"Sheet-1 List": [
{
"Id": 2,
"Title": "foo"
}
],
"LTAR": [
{
"Id": 2,
"Title": "foo"
}
]
},
{
"Id": 3,
"Title": "bar",
"SingleSelect": "b",
"Sheet-1 List": [],
"LTAR": []
}
],
"pageInfo": {
"totalRows": 3,
"page": 1,
"pageSize": 25,
"isFirstPage": true,
"isLastPage": true
}
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
}
},
"post": {
"summary": "Create Table View Row",
"operationId": "table-row-create",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"Example 1": {
"value": {
"Id": 1,
"col1": "foo",
"col2": "bar",
"CreatedAt": "2023-03-11T08:48:25.598Z",
"UpdatedAt": "2023-03-11T08:48:25.598Z"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": ["DB Table Row"],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"Example 1": {
"value": {
"col1": "foo",
"col2": "bar"
}
}
}
}
}
},
"description": "Create a new row in the given Table View"
}
},
"/api/v1/base/{projectId}/tables/{tableId}/count": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "projectId",
"in": "path",
"required": true,
"description": "Project Id"
},
{
"schema": {
"type": "string"
},
"name": "tableId",
"in": "path",
"required": true,
"description": "Table Id"
},
{
"schema": {
"type": "string"
},
"name": "viewId",
"in": "query",
"required": true
}
],
"get": {
"summary": "Count Table View Rows",
"operationId": "table-row-count",
"description": "Count how many rows in the given Table View",
"tags": ["DB Table Row"],
"parameters": [
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {},
"in": "query",
"name": "nested",
"description": "Query params for nested data"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"count": {
"type": "number",
"x-stoplight": {
"id": "hwq29x70rcipi"
}
}
}
},
"examples": {
"Example 1": {
"value": {
"count": 25
}
}
}
}
}
}
}
}
},
"/api/v1/db/tables/{tableId}/rows/{rowId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "tableId",
"in": "path",
"required": true,
"description": "Table Id"
},
{
"schema": {
"type": "string"
},
"name": "viewId",
"in": "query",
"required": true
},
{
"schema": {
"example": "1"
},
"name": "rowId",
"in": "path",
"required": true,
"description": "Unique Row ID"
}
],
"get": {
"summary": "Get Table View Row",
"operationId": "db-view-row-read",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {}
},
"examples": {
"Example 1": {
"value": {
"Id": 1,
"Title": "foo",
"CreatedAt": "2023-03-11T09:11:47.437Z",
"UpdatedAt": "2023-03-11T09:11:47.784Z"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"description": "Get the target Table View Row",
"tags": ["DB Table Row"],
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
}
]
},
"patch": {
"summary": "Update Table View Row",
"operationId": "table-row-update",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"Example 1": {
"value": {
"Id": 1,
"Title": "bar",
"CreatedAt": "2023-03-11T09:11:47.437Z",
"UpdatedAt": "2023-03-11T09:20:21.133Z"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": ["DB Table Row"],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"Example 1": {
"value": {
"Title": "bar"
}
}
}
}
}
},
"description": "Update the target Table View Row",
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
}
]
},
"delete": {
"summary": "Delete Table View Row",
"operationId": "table-row-delete",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "number"
},
"examples": {
"Example 1": {
"value": 1
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": ["DB Table Row"],
"description": "Delete the target Table View Row",
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
}
]
}
}
},
"components": {

Loading…
Cancel
Save