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

Local file reference does not appear to be working. #50

Open
trajano opened this issue Dec 4, 2024 · 3 comments
Open

Local file reference does not appear to be working. #50

trajano opened this issue Dec 4, 2024 · 3 comments

Comments

@trajano
Copy link

trajano commented Dec 4, 2024

I tried to use this with a JSON that contains local references which resolve using json-to-typescript

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Completed Quiz",
  "type": "object",
  "required": ["studentInfo", "evaluationInfo", "completedQuiz"],
  "properties": {
    "studentInfo": {
      "type": "object",
      "oneOf": [{ "$ref": "./XXXXStudent.schema.json" }]
    }
  }
}

But I get

C:\Users\trajano\AppData\Local\Volta\tools\image\packages\json-schema-faker-cli\node_modules\json-schema-faker-cli\node_modules\json-schema-faker\dist\main.cjs:2646
      throw new Error(`${e.message} in /${e.path.join("/")}`);
      ^

Error: Error: Reference not found: ./XXXXStudent.schema.json
    at recursiveUtil.resolveSchema (C:\Users\trajano\AppData\Local\Volta\tools\image\packages\json-schema-faker-cli\node_modules\json-schema-faker-cli\node_modules\json-schema-faker\dist\main.cjs:2497:21)

I verified that ./XXXXStudent.schema.json exists in the same folder.

@oprogramador
Copy link
Owner

Thanks for reporting this.

I've never used this tool with TypeScript so I cannot guarantee anything.

In this repo, there's not too much logic. It's mostly in this file: https://github.com/oprogramador/json-schema-faker-cli/blob/master/app/generate.js

So I don't believe that your error is caused by anything in this repo.

What do you mean by json-to-typescript? That repo with 0 stars: https://github.com/monolithed/json-to-typescript ? If so, that might be a likely cause of your issue.

Moreover, please double-check that all the required files exist, with exactly the expected file names (case sensitive), and that you run your command from the right directory.

@ksiczek
Copy link

ksiczek commented Mar 4, 2025

It has nothing to do with the TS I think. I have the schema separated into several definitions and reference them using relative paths but getting the error

/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2646
      throw new Error(`${e.message} in /${e.path.join("/")}`);
      ^

Error: Error: Prop not found: .. (../definitions.json#/definitions/Person)
    at Object.getLocalRef (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:1032:13)
    at recursiveUtil.resolveSchema (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2492:33)
    at /Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2550:39
    at Array.forEach (<anonymous>)
    at recursiveUtil.resolveSchema (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2548:26)
    at traverse (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2295:12)
    at Object.objectType [as object] (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2050:18)
    at traverse (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2375:48)
    at run (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2636:20)
    at jsf.generateWithContext (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:6412:14) in /
    at run (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:2646:13)
    at jsf.generateWithContext (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:6412:14)
    at jsf.generate (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/node_modules/json-schema-faker/dist/main.cjs:6415:11)
    at generate (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/app/generate.js:16:13)
    at Object.<anonymous> (/Users/karol.siczek/.nvm/versions/node/v22.11.0/lib/node_modules/json-schema-faker-cli/cmd.js:4:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)

@oprogramador
Copy link
Owner

@trajano @ksiczek

Does it work for you when you try absolute paths instead of relative paths?

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

3 participants