@@ -4,12 +4,13 @@ jest.mock("fs-extra", () => ({
4
4
} ) ) ;
5
5
6
6
import * as _fs from "fs-extra" ;
7
- import makeParseOpenRPCDocument from "./parse-open-rpc-document" ;
7
+ import makeParseOpenRPCDocument , { makeCustomResolver } from "./parse-open-rpc-document" ;
8
8
import { OpenrpcDocument as OpenRPC , OpenrpcDocument } from "@open-rpc/meta-schema" ;
9
9
import { OpenRPCDocumentValidationError } from "./validate-open-rpc-document" ;
10
10
import fetchUrlSchema from "./get-open-rpc-document-from-url" ;
11
11
import readSchemaFromFile from "./get-open-rpc-document-from-file" ;
12
12
import { OpenRPCDocumentDereferencingError } from "./dereference-document" ;
13
+ import { JSONSchema } from "@json-schema-tools/meta-schema" ;
13
14
14
15
const parseOpenRPCDocument = makeParseOpenRPCDocument ( fetchUrlSchema , readSchemaFromFile ) ;
15
16
const fs : any = _fs ;
@@ -248,6 +249,35 @@ describe("parseOpenRPCDocument", () => {
248
249
}
249
250
} ) ;
250
251
252
+ it ( "should make a reference resolver" , ( ) => {
253
+ const resolver = makeCustomResolver ( { "file" :
254
+ async ( ) : Promise < JSONSchema > => {
255
+ return { }
256
+ }
257
+ } ) ;
258
+ expect ( resolver ) . toBeDefined ( )
259
+ } ) ;
260
+
261
+ it ( "should handle dereference option true" , async ( ) => {
262
+ const document = await parseOpenRPCDocument ( workingDocument , {
263
+ dereference : true ,
264
+ } ) ;
265
+ expect ( document . methods ) . toBeDefined ( ) ;
266
+ } ) ;
267
+
268
+ it ( "should handle custom resolver option" , async ( ) => {
269
+ const resolver = makeCustomResolver ( { "handler" :
270
+ async ( uri : string ) : Promise < JSONSchema > => {
271
+ return { }
272
+ }
273
+ } ) ;
274
+ const document = await parseOpenRPCDocument ( workingDocument , {
275
+ resolver
276
+ } ) ;
277
+ expect ( document . methods ) . toBeDefined ( ) ;
278
+
279
+ } ) ;
280
+
251
281
it ( "rejects when the json provided is invalid from file" , async ( ) => {
252
282
expect . assertions ( 1 ) ;
253
283
fs . readJson . mockClear ( ) ;
0 commit comments