chore(api-doc): view collection api doc

This commit is contained in:
ChengLei Shao 2023-08-27 15:14:34 +08:00
parent 0fd38a5c56
commit 7fd126d6a3
4 changed files with 296 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import {
} from '@nocobase/database';
import multipleAssociation from './multiple-association';
import singleAssociation from './single-association';
import { isViewCollection } from '..';
export default (collection: Collection) => {
return associationFields(collection)
@ -27,6 +28,10 @@ export default (collection: Collection) => {
};
export function associationFields(collection: Collection): Array<RelationField> {
if (isViewCollection(collection)) {
return [];
}
return Array.from(collection.fields.values())
.filter((field) => field instanceof RelationField)
.filter((field) => field.name !== 'createdBy' && field.name !== 'updatedBy');

View File

@ -1,5 +1,5 @@
import { Collection, RelationField } from '@nocobase/database';
import { hasSortField } from './index';
import { hasSortField, readOnlyCollection } from './index';
type TemplateOptions = {
collection: Collection;
@ -327,11 +327,16 @@ export default (collection: Collection) => {
const apiDoc: any = {
[`/${collection.name}:list`]: ListActionTemplate(options),
[`/${collection.name}:get`]: GetActionTemplate(options),
[`/${collection.name}:create`]: CreateActionTemplate(options),
[`/${collection.name}:update`]: UpdateActionTemplate(options),
[`/${collection.name}:destroy`]: DestroyActionTemplate(options),
};
if (!readOnlyCollection(collection)) {
Object.assign(apiDoc, {
[`/${collection.name}:create`]: CreateActionTemplate(options),
[`/${collection.name}:update`]: UpdateActionTemplate(options),
[`/${collection.name}:destroy`]: DestroyActionTemplate(options),
});
}
if (hasSortField(collection)) {
apiDoc[`/${collection.name}:move`] = MoveActionTemplate(options);
}

View File

@ -5,7 +5,7 @@ import associations from './associations';
export default (collection: Collection, options) => {
const paths = list(collection);
if (options.withAssociation) {
if (options.withAssociation && !isViewCollection(collection)) {
Object.assign(paths, associations(collection));
}
@ -21,3 +21,11 @@ export function hasSortField(collection: Collection) {
return false;
}
export function readOnlyCollection(collection: Collection) {
return isViewCollection(collection) && collection.options?.writableView == false;
}
export function isViewCollection(collection: Collection) {
return collection.isView();
}

View File

@ -0,0 +1,273 @@
export default {
openapi: '3.0.2',
info: {
title: 'NocoBase API - Collection manager plugin',
},
tags: [],
paths: {
'/collections:list': {
get: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:get': {
get: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:create': {
post: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:update': {
post: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:destroy': {
post: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:move': {
post: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections:setFields': {
post: {
tags: ['collections'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:get': {
get: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:list': {
get: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:create': {
post: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:update': {
post: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:destroy': {
post: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collections/{collectionName}/fields:move': {
post: {
tags: ['collections.fields'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:list': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:get': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:create': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:update': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:destroy': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/collectionCategories:move': {
post: {
tags: ['collectionCategories'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/dbViews:get': {
get: {
tags: ['dbViews'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/dbViews:list': {
get: {
tags: ['dbViews'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
'/dbViews:query': {
get: {
tags: ['dbViews'],
description: '',
parameters: [],
responses: {
'200': {
description: 'OK',
},
},
},
},
},
};