diff --git a/packages/protons/src/index.ts b/packages/protons/src/index.ts index cc1f554..d26c19f 100644 --- a/packages/protons/src/index.ts +++ b/packages/protons/src/index.ts @@ -655,7 +655,7 @@ export async function generate (source: string, flags: Flags): Promise { const def = JSON.parse(json) - for (const [className, classDef] of Object.entries(def.nested)) { + for (const [className, classDef] of Object.entries(def.nested ?? {})) { for (const [fieldName, fieldDef] of Object.entries(classDef.fields ?? {})) { if (fieldDef.keyType == null) { continue diff --git a/packages/protons/test/fixtures/empty.proto b/packages/protons/test/fixtures/empty.proto new file mode 100644 index 0000000..e69de29 diff --git a/packages/protons/test/unsupported.spec.ts b/packages/protons/test/unsupported.spec.ts index 04759a9..1e9ad25 100644 --- a/packages/protons/test/unsupported.spec.ts +++ b/packages/protons/test/unsupported.spec.ts @@ -8,4 +8,9 @@ describe('unsupported', () => { await expect(generate('test/fixtures/proto2.proto', {})).to.eventually.be.rejected .with.property('message').that.contain('"required" fields are not allowed in proto3') }) + + it('should refuse to generate source from empty definition', async () => { + await expect(generate('test/fixtures/empty.proto', {})).to.eventually.be.rejected + .with.property('message').that.contain('No top-level messages found in protobuf') + }) })