Skip to content
Open
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
63 changes: 56 additions & 7 deletions src/dereference-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ describe("dereferenceDocument", () => {
...workingDocument,
"x-methods": {
foobar: {
name: "foobar",
params: [],
result: {
name: "abcfoo",
schema: { type: "number" }
}
}
name: "foobar",
params: [],
result: {
name: "abcfoo",
schema: { type: "number" }
}
}
},
components: {
schemas: {
Expand Down Expand Up @@ -330,6 +330,55 @@ describe("dereferenceDocument", () => {
expect(result.methods[0].result.schema.type).toBe("string")
});

it("works with ref to a nested file", async () => {
expect.assertions(2);

const testDoc = {
openrpc: "1.2.4",
info: {
title: "foo",
version: "1",
},
methods: [
{
name: "foo",
params: [],
result: {
name: "fooResult",
schema: { $ref: `${__dirname}/test-fixtures/nested-schema.json` }
}
}
]
};

const result = await dereferenceDocument(testDoc as OpenrpcDocument, defaultResolver) as any;

expect(result.methods[0].result.schema.type).toBe("object")
expect(result.methods[0].result.schema.properties.foo.type).toBe("string")
});

it("works with ref to a double nested file", async () => {
expect.assertions(2);

const testDoc = {
openrpc: "1.2.4",
info: {
title: "foo",
version: "1",
},
methods: [
{
"$ref": "./src/test-fixtures/method.json",
}
]
};

const result = await dereferenceDocument(testDoc as OpenrpcDocument, defaultResolver) as any;

expect(result.methods[0].result.schema.type).toBe("object")
expect(result.methods[0].result.schema.properties.foo.type).toBe("string")
});

it("works with schema that makes ref to a schema from components", async () => {
expect.assertions(1);

Expand Down
8 changes: 8 additions & 0 deletions src/test-fixtures/method.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "foo",
"params": [],
"result": {
"name": "fooResult",
"schema": { "$ref": "./nested-schema.json" }
}
}
8 changes: 8 additions & 0 deletions src/test-fixtures/nested-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "object",
"properties": {
"foo": {
"$ref": "./good-schema.json"
}
}
}