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);