GithubHelp home page GithubHelp logo

Comments (8)

jonluca avatar jonluca commented on May 24, 2024 1

@alexkaufman06 the issue with your example is that you are loading the yaml into an object in memory. This loses the information about where the file is on disk, so we have to fall back to making the relative references relative to the current working directory.

When you do

const fileContents = fs.readFileSync(`./api/${file}`, 'utf8');
const mySchema = yaml.load(fileContents);

The contents of mySchema does not contain its original location on disk - it does not know that it is in the api directory, so we now it falls back to thinking that we're in os.cwd(), which is the root folder.

I dont believe this is an issue with the library. Theres no way for us to know where the file is once you pass in an object and not a file path. If you change your code to pass in the file path instead, it works properly:

let clonedSchema = await $RefParser.dereference(./api/${file}, { mutateInputSchema: false });

CleanShot 2024-04-21 at 13 15 22@2x

CleanShot 2024-04-21 at 13 15 50@2x

from json-schema-ref-parser.

jonluca avatar jonluca commented on May 24, 2024

Can you share an example?

from json-schema-ref-parser.

alexkaufman06 avatar alexkaufman06 commented on May 24, 2024

Can you share an example?

Here is an example repo: https://github.com/alexkaufman06/example-issue
If you clone it and run npm i followed by npm run dref:json you should see an error opening file and no such directory.

If I change the refs from ../common/components to ./common/components it works but I don't think I should have to.

from json-schema-ref-parser.

alexkaufman06 avatar alexkaufman06 commented on May 24, 2024

@jonluca let me know if you need anymore info. Looks like this PR attempted to fix it but didn't have tests: https://github.com/APIDevTools/json-schema-ref-parser/pull/261/files

from json-schema-ref-parser.

denver-HJS avatar denver-HJS commented on May 24, 2024

I have this same issue in my repository. @jonluca would it make sense to resurrect #261?

from json-schema-ref-parser.

jonluca avatar jonluca commented on May 24, 2024

I have this same issue in my repository. @jonluca would it make sense to resurrect #261?

Does #261 solve a different issue? Could you include a separate relative referencing parsing error example?

from json-schema-ref-parser.

denver-HJS avatar denver-HJS commented on May 24, 2024

I have this same issue in my repository. @jonluca would it make sense to resurrect #261?

Does #261 solve a different issue? Could you include a separate relative referencing parsing error example?

Actually I was using the same approach as @alexkaufman06, so your suggestion addresses both of our issues/questions. Thank you for pointing us to the fix! 🙇

from json-schema-ref-parser.

alexkaufman06 avatar alexkaufman06 commented on May 24, 2024

Thanks for the fix @jonluca! 😅 🙇

from json-schema-ref-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.