Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Cannot find module '../dotjs/ref' #11

Closed
bjfletcher opened this issue Aug 23, 2015 · 7 comments
Closed

Cannot find module '../dotjs/ref' #11

bjfletcher opened this issue Aug 23, 2015 · 7 comments

Comments

@bjfletcher
Copy link

As of yesterday, in trying to run the mock service, immediately I get the following error:

Error: Cannot find module '../dotjs/ref'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/ben/SiteTour/projects/api/node_modules/osprey-mock-service/node_modules/osprey/node_modules/osprey-method-handler/node_modules/ajv/lib/compile/_rules.js:5:11)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

This is regression as it was working fine before yesterday. It seems that there's been a release with the AJV module that's causing problems here. I've asked on the AJV project about this: ajv-validator/ajv#38

It may be that we'll need to lock AJV version to 1.0.x in osprey-method-handler.

@blakeembrey
Copy link
Contributor

@bjfletcher Have you tried it since? The latest release, 1.1.1, should be working for you.

@bjfletcher
Copy link
Author

@blakeembrey This particular issue looks like to have been fixed. A very quick turnaround by @epoberezkin there, thanks. :)

I have a new issue:

Error: Unable to compile JSON schema for post /address: can't resolve reference http://json-schema.org/geo

which is probably some unrelated issue so I'll just close this AJV issue.

Thanks @blakeembrey :)

@blakeembrey
Copy link
Contributor

@bjfletcher Right now Osprey isn't resolving external schemas. Did this work with older versions of Osprey or the mocking service?

Edit: It shouldn't have worked with older versions, there was never any external resolve logic there. However, it's possible to add this as a feature in the future. It'll just change the API quite a bit to support resolving async dependencies.

@bjfletcher
Copy link
Author

@blakeembrey Great, thanks for this clarity. It's very much appreciated.

Is there an issue raised for external schemas support? I'd like to follow it.

@blakeembrey
Copy link
Contributor

There is not right now, but you're welcome to create one (or I can) here https://github.com/mulesoft-labs/osprey-method-handler/issues

@epoberezkin
Copy link

ajv allows adding "external" referenced schemas, but they have to be added before compilation. I was thinking about the use case when the schema comes from some external (hopefully trusted) source so that it is not known which schemas are referenced from it. Although I don't want to implement any asynchronous loading in ajv, I was thinking that the exception that ajv throws when the schema is missing can contain the missing schema URI so that the user can load it, add it to ajv instance and call compile again (this process can be repeated multiple times until all references are resolved).

What do you think?

@blakeembrey
Copy link
Contributor

@epoberezkin Sounds like a good idea. I wouldn't want to do asynchronous loading from the library either, which is why I was still on the fence about the appropriate API in Osprey for this (failures need to occur/register well before the route is being loaded).

@bjfletcher I think a good solution for Osprey in the meantime is to expose the addSchema method of AJV through the Osprey interface so it can be pre-registered before Osprey is loaded. This maintains backward-compatibility and allows people to store schemas locally which removes the burden from having remote references to JSON schema. However, in the mocking service situation it's a little messier (as it should just work), so I'll implement a flag that pulls the files in (either by traversing the schemas or by catching the errors @epoberezkin throws) and caches them locally for the mocking service.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants