From db9e029ca2bee3b8f53a0ccc9ed65bab82597fb3 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 10 Aug 2022 23:42:26 +0530 Subject: [PATCH] fix(swagger): type corrections Signed-off-by: Pranav C --- .../components/smartsheet/sidebar/MenuTop.vue | 1 - .../components/tabs/auth/UserManagement.vue | 2 +- .../tabs/auth/user-management/ShareBase.vue | 6 +- .../nc-gui-v2/composables/useViewColumns.ts | 4 +- packages/nc-gui-v2/composables/useViews.ts | 5 +- packages/nocodb-sdk/src/lib/Api.ts | 26 +++--- packages/nocodb/src/lib/models/User.ts | 2 +- scripts/sdk/swagger.json | 82 ++++++++++++------- .../http-clients/axios-http-client.eta | 2 +- .../http-clients/fetch-http-client.eta | 4 +- 10 files changed, 76 insertions(+), 58 deletions(-) diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue index 1800b9e3b7..a59f8c94f9 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue @@ -151,7 +151,6 @@ async function onRename(view: ViewType) { } try { - // todo typing issues, order and id do not exist on all members of ViewTypes (Kanban, Gallery, Form, Grid) await api.dbView.update(view.id!, { title: view.title, order: view.order, diff --git a/packages/nc-gui-v2/components/tabs/auth/UserManagement.vue b/packages/nc-gui-v2/components/tabs/auth/UserManagement.vue index 69797b8f40..7b6c35106e 100644 --- a/packages/nc-gui-v2/components/tabs/auth/UserManagement.vue +++ b/packages/nc-gui-v2/components/tabs/auth/UserManagement.vue @@ -39,7 +39,7 @@ const loadUsers = async (page = currentPage, limit = currentLimit) => { if (!project.value?.id) return // TODO: Types of api is not correct - const response = await $api.auth.projectUserList(project.value?.id, { + const response: any = await $api.auth.projectUserList(project.value?.id, { query: { limit, offset: searchText.value.length === 0 ? (page - 1) * limit : 0, diff --git a/packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue b/packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue index cdd6506c1c..a255015511 100644 --- a/packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue +++ b/packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue @@ -32,8 +32,7 @@ const loadBase = async () => { try { if (!project.value.id) return - // todo: result is missing roles in return-type - const res: any = await $api.project.sharedBaseGet(project.value.id) + const res = await $api.project.sharedBaseGet(project.value.id) base = { uuid: res.uuid, url: res.url, @@ -50,8 +49,7 @@ const createShareBase = async (role = ShareBaseRole.Viewer) => { try { if (!project.value.id) return - // todo: returns void? - const res: any = await $api.project.sharedBaseUpdate(project.value.id, { + const res = await $api.project.sharedBaseUpdate(project.value.id, { roles: role, }) diff --git a/packages/nc-gui-v2/composables/useViewColumns.ts b/packages/nc-gui-v2/composables/useViewColumns.ts index 5f4fb26b7d..406620b745 100644 --- a/packages/nc-gui-v2/composables/useViewColumns.ts +++ b/packages/nc-gui-v2/composables/useViewColumns.ts @@ -1,11 +1,11 @@ import { isSystemColumn } from 'nocodb-sdk' -import type { ColumnType, FormType, GalleryType, GridType, TableType } from 'nocodb-sdk' +import type { ColumnType, FormType, GalleryType, GridType, TableType, ViewType } from 'nocodb-sdk' import { watch } from 'vue' import type { ComputedRef, Ref } from 'vue' import { useNuxtApp } from '#app' export function useViewColumns( - view: Ref<(GridType | FormType | GalleryType) & { id?: string }> | undefined, + view: Ref | undefined, meta: ComputedRef, isPublic = false, reloadData?: () => void, diff --git a/packages/nc-gui-v2/composables/useViews.ts b/packages/nc-gui-v2/composables/useViews.ts index 40fc4ddc93..854852f003 100644 --- a/packages/nc-gui-v2/composables/useViews.ts +++ b/packages/nc-gui-v2/composables/useViews.ts @@ -10,10 +10,9 @@ export function useViews(meta: MaybeRef) { const _meta = unref(meta) if (_meta && _meta.id) { - // todo: swagger type correction - const response = (await $api.dbView.list(_meta.id)).list as any[] + const response = (await $api.dbView.list(_meta.id)).list if (response) { - views = response.sort((a, b) => a.order - b.order) + views = response.sort((a, b) => a.order! - b.order!) } } } diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index f8ff88bfb5..2953e6a899 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -11,13 +11,16 @@ export interface UserType { /** Unique identifier for the given user. */ - id: number; + id: string; firstname: string; lastname: string; /** @format email */ email: string; + /** @format email */ + roles?: string; + /** * @format date * @example 1997-10-31 @@ -127,6 +130,7 @@ export interface ViewType { order?: number; fk_model_id?: string; slug?: string; + show_system_fields?: boolean; lock_type?: 'collaborative' | 'locked' | 'personal'; } @@ -436,7 +440,7 @@ export interface SharedViewListType { } export interface ViewListType { - list?: GridType | FormType | KanbanType | GalleryType; + list?: ViewType[]; pageInfo?: PaginatedType; } @@ -661,10 +665,7 @@ export interface FullRequestParams body?: unknown; } -export type RequestParams = Omit< - FullRequestParams, - 'body' | 'method' | 'query' | 'path' ->; +export type RequestParams = Omit; export interface ApiConfig extends Omit { @@ -1271,10 +1272,10 @@ export class Api< * @tags Project * @name SharedBaseGet * @request GET:/api/v1/db/meta/projects/{projectId}/shared - * @response `200` `{ uuid?: string, url?: string }` OK + * @response `200` `{ uuid?: string, url?: string, roles?: string }` OK */ sharedBaseGet: (projectId: string, params: RequestParams = {}) => - this.request<{ uuid?: string; url?: string }, any>({ + this.request<{ uuid?: string; url?: string; roles?: string }, any>({ path: `/api/v1/db/meta/projects/${projectId}/shared`, method: 'GET', format: 'json', @@ -1302,14 +1303,14 @@ export class Api< * @tags Project * @name SharedBaseCreate * @request POST:/api/v1/db/meta/projects/{projectId}/shared - * @response `200` `{ url?: string, uuid?: string }` OK + * @response `200` `{ uuid?: string, url?: string, roles?: string }` OK */ sharedBaseCreate: ( projectId: string, data: { roles?: string; password?: string }, params: RequestParams = {} ) => - this.request<{ url?: string; uuid?: string }, any>({ + this.request<{ uuid?: string; url?: string; roles?: string }, any>({ path: `/api/v1/db/meta/projects/${projectId}/shared`, method: 'POST', body: data, @@ -1324,18 +1325,19 @@ export class Api< * @tags Project * @name SharedBaseUpdate * @request PATCH:/api/v1/db/meta/projects/{projectId}/shared - * @response `200` `void` OK + * @response `200` `{ uuid?: string, url?: string, roles?: string }` OK */ sharedBaseUpdate: ( projectId: string, data: { roles?: string; password?: string }, params: RequestParams = {} ) => - this.request({ + this.request<{ uuid?: string; url?: string; roles?: string }, any>({ path: `/api/v1/db/meta/projects/${projectId}/shared`, method: 'PATCH', body: data, type: ContentType.Json, + format: 'json', ...params, }), diff --git a/packages/nocodb/src/lib/models/User.ts b/packages/nocodb/src/lib/models/User.ts index c983a5ae25..3e24027f60 100644 --- a/packages/nocodb/src/lib/models/User.ts +++ b/packages/nocodb/src/lib/models/User.ts @@ -4,7 +4,7 @@ import Noco from '../Noco'; import extractProps from '../meta/helpers/extractProps'; import NocoCache from '../cache/NocoCache'; export default class User implements UserType { - id: number; + id: string; /** @format email */ email: string; diff --git a/scripts/sdk/swagger.json b/scripts/sdk/swagger.json index ae0930d643..b6656f5b49 100644 --- a/scripts/sdk/swagger.json +++ b/scripts/sdk/swagger.json @@ -916,6 +916,9 @@ }, "url": { "type": "string" + }, + "roles": { + "type": "string" } } } @@ -939,25 +942,27 @@ "post": { "summary": "", "operationId": "project-shared-base-create", - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "url": { - "type": "string" - }, - "uuid": { - "type": "string" - } + "responses": { "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "uuid": { + "type": "string" + }, + "url": { + "type": "string" + }, + "roles": { + "type": "string" } } } } } + } }, "tags": [ "Project" @@ -985,7 +990,25 @@ "operationId": "project-shared-base-update", "responses": { "200": { - "description": "OK" + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "uuid": { + "type": "string" + }, + "url": { + "type": "string" + }, + "roles": { + "type": "string" + } + } + } + } + } } }, "requestBody": { @@ -5444,7 +5467,7 @@ "description": "", "examples": [ { - "id": 142, + "id": "142", "firstName": "Alice", "lastName": "Smith", "email": "alice.smith@gmail.com", @@ -5456,7 +5479,7 @@ "x-internal": false, "properties": { "id": { - "type": "integer", + "type": "string", "description": "Unique identifier for the given user." }, "firstname": { @@ -5469,6 +5492,10 @@ "type": "string", "format": "email" }, + "roles": { + "type": "string", + "format": "email" + }, "date_of_birth": { "type": "string", "format": "date", @@ -6026,6 +6053,9 @@ "slug": { "type": "string" }, + "show_system_fields": { + "type": "boolean" + }, "lock_type": { "type": "string", "enum": [ @@ -7356,20 +7386,10 @@ }, "properties": { "list": { - "oneOf": [ - { - "$ref": "#/components/schemas/Grid" - }, - { - "$ref": "#/components/schemas/Form" - }, - { - "$ref": "#/components/schemas/Kanban" - }, - { - "$ref": "#/components/schemas/Gallery" - } - ] + "type": "array", + "items": { + "$ref": "#/components/schemas/View" + } }, "pageInfo": { "$ref": "#/components/schemas/Paginated" diff --git a/scripts/sdk/templates/http-clients/axios-http-client.eta b/scripts/sdk/templates/http-clients/axios-http-client.eta index c81bdc4e4d..3bcd3c75f2 100644 --- a/scripts/sdk/templates/http-clients/axios-http-client.eta +++ b/scripts/sdk/templates/http-clients/axios-http-client.eta @@ -23,7 +23,7 @@ export interface FullRequestParams extends Omit; +export type RequestParams = Omit; export interface ApiConfig extends Omit { securityWorker?: (securityData: SecurityDataType | null) => Promise | AxiosRequestConfig | void; diff --git a/scripts/sdk/templates/http-clients/fetch-http-client.eta b/scripts/sdk/templates/http-clients/fetch-http-client.eta index 0477e0b70f..b811731543 100644 --- a/scripts/sdk/templates/http-clients/fetch-http-client.eta +++ b/scripts/sdk/templates/http-clients/fetch-http-client.eta @@ -24,7 +24,7 @@ export interface FullRequestParams extends Omit { cancelToken?: CancelToken; } -export type RequestParams = Omit +export type RequestParams = Omit export interface ApiConfig { @@ -68,7 +68,7 @@ export class HttpClient { public setSecurityData = (data: SecurityDataType | null) => { this.securityData = data; } - + private encodeQueryParam(key: string, value: any) { const encodedKey = encodeURIComponent(key); return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;