diff --git a/src/dereference-document.ts b/src/dereference-document.ts index 7ddb8fbe..2cfb0371 100644 --- a/src/dereference-document.ts +++ b/src/dereference-document.ts @@ -143,7 +143,9 @@ const handleMethod = async (methodOrRef: MethodOrReference, doc: OpenrpcDocument } method.params = await derefItems(method.params as ReferenceObject[], doc, resolver); - method.result = await derefItem(method.result as ReferenceObject, doc, resolver); + if (method.result !== undefined) { + method.result = await derefItem(method.result as ReferenceObject, doc, resolver); + } let componentSchemas: SchemaComponents = {}; @@ -157,8 +159,10 @@ const handleMethod = async (methodOrRef: MethodOrReference, doc: OpenrpcDocument p.schema = await handleSchemaWithSchemaComponents(p.schema, componentSchemas); } - const result = method.result as ContentDescriptorObject; - result.schema = await handleSchemaWithSchemaComponents(result.schema, componentSchemas); + if (method.result !== undefined) { + const result = method.result as ContentDescriptorObject; + result.schema = await handleSchemaWithSchemaComponents(result.schema, componentSchemas); + } return method; }; diff --git a/src/parse-open-rpc-document.test.ts b/src/parse-open-rpc-document.test.ts index 39168c68..1976313f 100644 --- a/src/parse-open-rpc-document.test.ts +++ b/src/parse-open-rpc-document.test.ts @@ -24,6 +24,20 @@ const workingDocument: OpenRPC = { openrpc: "1.0.0-rc1", }; +const notificationDocument: OpenRPC = { + ...workingDocument, + methods: [ + { + name: "foo", + params: [ + { + name: "bar", + schema: { "type": "boolean" }, + }, + ], + }, + ], +}; const badRefDocument: OpenRPC = { ...workingDocument, methods: [ @@ -101,6 +115,12 @@ describe("parseOpenRPCDocument", () => { expect(document.methods).toBeDefined(); }); + it("handles being passed an open rpc object with notification", async () => { + expect.assertions(1); + const document = await parseOpenRPCDocument(notificationDocument); + expect(document.methods).toBeDefined(); + }); + it("can disable validation", async () => { expect.assertions(1); const document = await parseOpenRPCDocument(invalidDocument, { validate: false });