From 60b0fdd5cadb674dc4db35c315bd3a56cfca580c Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Thu, 24 Aug 2023 09:50:33 +0800 Subject: [PATCH] chore: catch api doc collection error --- .../server/swagger/collections/components/parameters.ts | 5 +++++ packages/plugins/api-doc/src/server/swagger/index.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/plugins/api-doc/src/server/swagger/collections/components/parameters.ts b/packages/plugins/api-doc/src/server/swagger/collections/components/parameters.ts index c78140385a..18cf3b9ae9 100644 --- a/packages/plugins/api-doc/src/server/swagger/collections/components/parameters.ts +++ b/packages/plugins/api-doc/src/server/swagger/collections/components/parameters.ts @@ -7,6 +7,11 @@ export default (collection: Collection) => { const parameters = {}; if (primaryKey) { + const primaryKeyField = collection.fields.get(primaryKey); + if (!primaryKeyField) { + throw new Error(`primaryKeyField not found: ${primaryKey}, ${collection.name}`); + } + Object.assign(parameters, { collectionIndex: { required: true, diff --git a/packages/plugins/api-doc/src/server/swagger/index.ts b/packages/plugins/api-doc/src/server/swagger/index.ts index c2a16a7791..39cb587e14 100644 --- a/packages/plugins/api-doc/src/server/swagger/index.ts +++ b/packages/plugins/api-doc/src/server/swagger/index.ts @@ -52,11 +52,17 @@ export class SwaggerManager { 'hidden.$isFalsy': true, }, }); + for (const collection of collections) { if (collection.name === 'roles') { continue; } - others = merge(others, this.collection2Swagger(collection.name, false)); + + try { + others = merge(others, this.collection2Swagger(collection.name, false)); + } catch (e) { + this.app.log.error(e); + } } } return merge(base, others);