Browse Source

Merge pull request #6787 from nocodb/fix/6477-swagger-schema

fix: Swagger schema corrections
pull/6805/head
Raju Udava 1 year ago committed by GitHub
parent
commit
435f3fed8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      packages/nocodb/src/services/api-docs/swagger/getSwaggerColumnMetas.ts
  2. 4
      packages/nocodb/src/services/api-docs/swagger/templates/params.ts

13
packages/nocodb/src/services/api-docs/swagger/getSwaggerColumnMetas.ts

@ -1,4 +1,4 @@
import { UITypes } from 'nocodb-sdk'; import { RelationTypes, UITypes } from 'nocodb-sdk';
import type { Base, Column, LinkToAnotherRecordColumn } from '~/models'; import type { Base, Column, LinkToAnotherRecordColumn } from '~/models';
import SwaggerTypes from '~/db/sql-mgr/code/routers/xc-ts/SwaggerTypes'; import SwaggerTypes from '~/db/sql-mgr/code/routers/xc-ts/SwaggerTypes';
import Noco from '~/Noco'; import Noco from '~/Noco';
@ -26,8 +26,15 @@ export default async (
); );
if (colOpt) { if (colOpt) {
const relTable = await colOpt.getRelatedTable(ncMeta); const relTable = await colOpt.getRelatedTable(ncMeta);
field.type = undefined; if (colOpt.type === RelationTypes.BELONGS_TO) {
field.$ref = `#/components/schemas/${relTable.title}Request`; field.type = undefined;
field.$ref = `#/components/schemas/${relTable.title}Request`;
} else {
field.type = 'array';
field.items = {
$ref: `#/components/schemas/${relTable.title}Request`,
};
}
} }
} }
break; break;

4
packages/nocodb/src/services/api-docs/swagger/templates/params.ts

@ -197,6 +197,10 @@ export const getNestedParams = async (
): Promise<any[]> => { ): Promise<any[]> => {
return await columns.reduce(async (paramsArr, { column }) => { return await columns.reduce(async (paramsArr, { column }) => {
if (column.uidt === UITypes.LinkToAnotherRecord) { if (column.uidt === UITypes.LinkToAnotherRecord) {
// exclude system columns(relations to junction table)
if (column.system) {
return paramsArr;
}
const colOpt = await column.getColOptions<LinkToAnotherRecordColumn>(); const colOpt = await column.getColOptions<LinkToAnotherRecordColumn>();
if (colOpt.type !== RelationTypes.BELONGS_TO) { if (colOpt.type !== RelationTypes.BELONGS_TO) {
return [ return [

Loading…
Cancel
Save