Skip to content

Commit

Permalink
Merge pull request #895 from amanusk/fix/parse_notifications
Browse files Browse the repository at this point in the history
fix: parse notifications
  • Loading branch information
BelfordZ authored Jun 27, 2024
2 parents c6ddc64 + 7c81f67 commit 86805d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/dereference-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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;
};
Expand Down
20 changes: 20 additions & 0 deletions src/parse-open-rpc-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 86805d8

Please sign in to comment.