Browse Source

feat(nocodb): map swagger schema for api payload validation

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5174/head
Pranav C 2 years ago
parent
commit
8fea468925
  1. 4
      packages/nc-gui/components.d.ts
  2. 43
      packages/nocodb-sdk/src/lib/Api.ts
  3. 1
      packages/nocodb/src/lib/meta/api/ajvSchemas/index.ts
  4. 5
      packages/nocodb/src/lib/meta/api/columnApis.ts
  5. 4
      packages/nocodb/src/lib/meta/api/filterApis.ts
  6. 4
      packages/nocodb/src/lib/meta/api/hookApis.ts
  7. 3
      packages/nocodb/src/lib/meta/api/projectApis.ts
  8. 3
      packages/nocodb/src/lib/meta/api/sortApis.ts
  9. 3
      packages/nocodb/src/lib/meta/api/tableApis.ts
  10. 151
      scripts/sdk/swagger.json

4
packages/nc-gui/components.d.ts vendored

@ -251,8 +251,12 @@ declare module '@vue/runtime-core' {
NcIconsRowHeightMedium: typeof import('~icons/nc-icons/row-height-medium')['default']
NcIconsRowHeightShort: typeof import('~icons/nc-icons/row-height-short')['default']
NcIconsRowHeightTall: typeof import('~icons/nc-icons/row-height-tall')['default']
PhChatTextThin: typeof import('~icons/ph/chat-text-thin')['default']
PhCloudLightningDuotone: typeof import('~icons/ph/cloud-lightning-duotone')['default']
PhCloudLightningThin: typeof import('~icons/ph/cloud-lightning-thin')['default']
PhFileCsv: typeof import('~icons/ph/file-csv')['default']
PhUserPlusThin: typeof import('~icons/ph/user-plus-thin')['default']
PhUsersThreeThin: typeof import('~icons/ph/users-three-thin')['default']
RiLineHeight: typeof import('~icons/ri/line-height')['default']
RiTeamFill: typeof import('~icons/ri/team-fill')['default']
RouterLink: typeof import('vue-router')['RouterLink']

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

@ -45,7 +45,7 @@ export interface UserListType {
}
export interface ProjectReqType {
title?: string;
title: string;
description?: string;
color?: string;
bases?: BaseReqType[];
@ -201,6 +201,22 @@ export interface FilterType {
fk_hook_id?: string;
}
export interface FilterReqType {
id?: string;
fk_model_id?: string;
fk_column_id?: string;
logical_op?: string;
comparison_op?: string;
value?: string | number | boolean | null;
is_group?: boolean;
children?: FilterType[];
project_id?: string;
base_id?: string;
fk_parent_id?: string;
fk_view_id?: string;
fk_hook_id?: string;
}
export interface FilterListType {
filters: {
list: FilterType[];
@ -543,6 +559,31 @@ export interface HookType {
active?: boolean;
}
export interface HookReqType {
id?: string;
fk_model_id?: string;
title: string;
description?: string;
env?: string;
event: 'after' | 'before';
operation: 'insert' | 'delete' | 'update';
async?: boolean;
payload?: string;
url?: string;
headers?: string;
condition?: boolean;
notification: object;
retries?: number;
retry_interval?: number;
timeout?: number;
active?: boolean;
}
export interface HookTestReqType {
payload: any;
hook: HookReqType;
}
export interface PluginType {
id?: string;
title?: string;

1
packages/nocodb/src/lib/meta/api/ajvSchemas/index.ts

@ -0,0 +1 @@
export * from './ajiAjv'

5
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -40,12 +40,12 @@ import { MetaTable } from '../../utils/globals';
import formulaQueryBuilderv2 from '../../db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2';
import {
createHmAndBtColumn,
generateFkName,
generateFkName, getAjvValidatorMw,
randomID,
validateLookupPayload,
validateRequiredField,
validateRollupPayload,
} from './helpers';
} from './helpers'
export enum Altered {
NEW_COLUMN = 1,
@ -1785,6 +1785,7 @@ const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/tables/:tableId/columns/',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/ColumnReq'),
ncMetaAclMw(columnAdd, 'columnAdd')
);

4
packages/nocodb/src/lib/meta/api/filterApis.ts

@ -13,6 +13,7 @@ import Project from '../../models/Project';
import Filter from '../../models/Filter';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
// @ts-ignore
export async function filterGet(req: Request, res: Response, next) {
@ -135,6 +136,7 @@ router.get(
router.post(
'/api/v1/db/meta/views/:viewId/filters',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/filterReq'),
ncMetaAclMw(filterCreate, 'filterCreate')
);
@ -145,6 +147,7 @@ router.get(
router.post(
'/api/v1/db/meta/hooks/:hookId/filters',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/filterReq'),
ncMetaAclMw(hookFilterCreate, 'filterCreate')
);
@ -156,6 +159,7 @@ router.get(
router.patch(
'/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/filterReq'),
ncMetaAclMw(filterUpdate, 'filterUpdate')
);
router.delete(

4
packages/nocodb/src/lib/meta/api/hookApis.ts

@ -9,6 +9,7 @@ import Model from '../../models/Model';
import populateSamplePayload from '../helpers/populateSamplePayload';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
export async function hookList(
req: Request<any, any, any>,
@ -85,11 +86,13 @@ router.get(
router.post(
'/api/v1/db/meta/tables/:tableId/hooks/test',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/HookTestReq'),
ncMetaAclMw(hookTest, 'hookTest')
);
router.post(
'/api/v1/db/meta/tables/:tableId/hooks',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/HookReq'),
ncMetaAclMw(hookCreate, 'hookCreate')
);
router.delete(
@ -100,6 +103,7 @@ router.delete(
router.patch(
'/api/v1/db/meta/hooks/:hookId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/HookReq'),
ncMetaAclMw(hookUpdate, 'hookUpdate')
);
router.get(

3
packages/nocodb/src/lib/meta/api/projectApis.ts

@ -18,7 +18,7 @@ import { metaApiMetrics } from '../helpers/apiMetrics';
import { extractPropsAndSanitize } from '../helpers/extractProps';
import NcConfigFactory from '../../utils/NcConfigFactory';
import { promisify } from 'util';
import { populateMeta } from './helpers';
import { getAjvValidatorMw, populateMeta } from './helpers'
import Filter from '../../models/Filter';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -272,6 +272,7 @@ export default (router) => {
router.post(
'/api/v1/db/meta/projects',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/ProjectReq'),
ncMetaAclMw(projectCreate, 'projectCreate')
);
router.get(

3
packages/nocodb/src/lib/meta/api/sortApis.ts

@ -12,6 +12,7 @@ import Project from '../../models/Project';
import Sort from '../../models/Sort';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
// @ts-ignore
export async function sortGet(req: Request, res: Response<TableType>) {}
@ -58,6 +59,7 @@ router.get(
router.post(
'/api/v1/db/meta/views/:viewId/sorts/',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/sortReq'),
ncMetaAclMw(sortCreate, 'sortCreate')
);
router.get(
@ -68,6 +70,7 @@ router.get(
router.patch(
'/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/sortReq'),
ncMetaAclMw(sortUpdate, 'sortUpdate')
);
router.delete(

3
packages/nocodb/src/lib/meta/api/tableApis.ts

@ -17,6 +17,7 @@ import ProjectMgrv2 from '../../db/sql-mgr/v2/ProjectMgrv2';
import Project from '../../models/Project';
import Audit from '../../models/Audit';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { getAjvValidatorMw } from './helpers'
import { xcVisibilityMetaGet } from './modelVisibilityApis';
import View from '../../models/View';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
@ -410,11 +411,13 @@ router.get(
router.post(
'/api/v1/db/meta/projects/:projectId/tables',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/TableReq'),
ncMetaAclMw(tableCreate, 'tableCreate')
);
router.post(
'/api/v1/db/meta/projects/:projectId/:baseId/tables',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/TableReq'),
ncMetaAclMw(tableCreate, 'tableCreate')
);
router.get(

151
scripts/sdk/swagger.json

@ -7318,7 +7318,10 @@
"$ref": "#/components/schemas/BaseReq"
}
}
}
},
"required": [
"title"
]
},
"Project": {
"title": "Project",
@ -8128,6 +8131,63 @@
},
"readOnly": true
},
"FilterReq": {
"type": "object",
"title": "Filter",
"properties": {
"id": {
"type": "string"
},
"fk_model_id": {
"type": "string"
},
"fk_column_id": {
"type": "string"
},
"logical_op": {
"type": "string"
},
"comparison_op": {
"type": "string"
},
"value": {
"type": [
"string",
"number",
"integer",
"boolean",
"null"
]
},
"is_group": {
"type": "boolean"
},
"children": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Filter"
}
},
"project_id": {
"type": "string",
"readOnly": true
},
"base_id": {
"type": "string",
"readOnly": true
},
"fk_parent_id": {
"type": "string"
},
"fk_view_id": {
"type": "string"
},
"fk_hook_id": {
"type": "string"
}
},
"readOnly": true
},
"FilterList": {
"description": "",
"type": "object",
@ -9396,6 +9456,93 @@
}
}
},
"HookReq": {
"title": "AuditType",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"fk_model_id": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"env": {
"type": "string"
},
"event": {
"type": "string",
"enum": [
"after",
"before"
]
},
"operation": {
"type": "string",
"enum": [
"insert",
"delete",
"update"
]
},
"async": {
"type": "boolean"
},
"payload": {
"type": "string"
},
"url": {
"type": "string"
},
"headers": {
"type": "string"
},
"condition": {
"type": "boolean"
},
"notification": {
"type": "object"
},
"retries": {
"type": "number"
},
"retry_interval": {
"type": "number"
},
"timeout": {
"type": "number"
},
"active": {
"type": "boolean"
}
},
"required": [
"title",
"event",
"notification",
"operation"
]
},
"HookTestReq": {
"title": "Hook test request payload",
"type": "object",
"properties": {
"payload": {},
"hook": {
"$ref": "#/components/schemas/HookReq"
}
},
"required": [
"payload",
"hook"
]
},
"Plugin": {
"title": "Plugin",
"type": "object",
@ -10309,4 +10456,4 @@
}
}
}
}
}

Loading…
Cancel
Save