Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse notifications #895

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/dereference-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

try {
// returns resolved value of the reference
return (await resolver.resolve($ref, doc) as any);

Check warning on line 30 in src/dereference-document.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
} catch (err: any) {

Check warning on line 31 in src/dereference-document.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
throw new OpenRPCDocumentDereferencingError([
`unable to eval pointer against OpenRPC Document.`,
`error type: ${err.name}`,
Expand Down Expand Up @@ -64,7 +64,7 @@
delete dereffed.components;
}
return dereffed;
} catch (e: any) {

Check warning on line 67 in src/dereference-document.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
throw new OpenRPCDocumentDereferencingError([
"Unable to parse reference inside of JSONSchema",
s.title ? `Schema Title: ${s.title}` : "",
Expand Down Expand Up @@ -143,7 +143,9 @@
}

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 @@
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 Expand Up @@ -192,7 +196,7 @@

derefDoc = await handleSchemaComponents(derefDoc);
derefDoc = await handleSchemasInsideContentDescriptorComponents(derefDoc);
const methods = [] as any;

Check warning on line 199 in src/dereference-document.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const method of derefDoc.methods) {
methods.push(await handleMethod(method, derefDoc, resolver));
}
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
Loading