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

Loading schema from file system doesn't work on Windows #4

Closed
ralfhandl opened this issue Aug 2, 2024 · 4 comments
Closed

Loading schema from file system doesn't work on Windows #4

ralfhandl opened this issue Aug 2, 2024 · 4 comments

Comments

@ralfhandl
Copy link

ralfhandl commented Aug 2, 2024

Problem

Trying to load a schema from a relative location in the file system fails on Windows:

const validateOpenApi = await validate("./schemas/v3.1/schema.json");

results in

RetrievalError: Unable to load resource 'file:///C:/git/OpenAPI-Specification/schemas/v3.1/schema.json'.
 ❯ get node_modules/@hyperjump/browser/lib/browser/browser.js:29:13
 ❯ getSchema node_modules/@hyperjump/json-schema/lib/schema.js:31:18
 ❯ Module.validate node_modules/@hyperjump/json-schema/lib/core.js:21:18
 ❯ tests/v3.1/examples.test.js:14:25

How to reproduce

git clone https://github.com/OAI/OpenAPI-Specification
cd OpenAPI-Specification
npm i
npm t

Workaround

Fetching the schema from the file system and registering it works:

registerSchema(JSON.parse(readFileSync("./schemas/v3.1/schema.json","utf8")),"http://localhost/schema");
const validateOpenApi = await validate("http://localhost/schema");

This is rather clumsy and not the documented preferred way to work with file-based schemas on the server.

@jdesrosiers
Copy link
Collaborator

Thanks for reporting. I'll look into it.

@jdesrosiers
Copy link
Collaborator

I've identified the problem to be in @hyperjump/browser, so I'm moving the issue there.

@jdesrosiers jdesrosiers transferred this issue from hyperjump-io/json-schema Aug 5, 2024
@jdesrosiers
Copy link
Collaborator

This should be fixed now. I also took the opportunity to add automation for running test on windows, so hopefully going forward windows-specific bugs will be caught earlier.

Please update your dependencies and let me know if you have any more problems. The version of @hyperjump/browser should be 1.1.6.

@ralfhandl
Copy link
Author

@jdesrosiers Works like a charm now, thanks!

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

No branches or pull requests

2 participants