Skip to content

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

Closed
@ralfhandl

Description

@ralfhandl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions