Comments (8)
@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 });
from json-schema-ref-parser.
Can you share an example?
from json-schema-ref-parser.
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.
@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.
I have this same issue in my repository. @jonluca would it make sense to resurrect #261?
from json-schema-ref-parser.
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.
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.
Thanks for the fix @jonluca! 😅 🙇
from json-schema-ref-parser.
Related Issues (20)
- Changelog for version 10.0.0 seems to be missing HOT 1
- Types ResolverOptions and FileInfo are no longer exported in v11 HOT 1
- Numbers being appended to the TypeScript interface names when using the same $ref multiple times HOT 1
- unwanted
- clonedeep vs structuredClone HOT 2
- win32 not available when using webpack 5 and path-browserify polyfill HOT 1
- Remap incorrectly using escaped paths HOT 1
- Prototype Pollution vulnerability affecting @apidevtools/json-schema-ref-parser, versions 11.0.0, 11.1.0 HOT 1
- Module Not Found HOT 4
- bundle() creates a invalid $ref HOT 7
- Dereferencing time out HOT 1
- Exclude $id from dereferenced schemas HOT 2
- Unable to de-reference nested array in parsed JSON response HOT 2
- How to get rid of the circular reference error HOT 2
- I'm getting this error while using $RefParser.derefernce in angular ionic HOT 4
- Possibility to add `onBundle` callback? HOT 1
- Unable to dereference discriminator mappings HOT 1
- Replacement-value is presumably passed by reference instead of being passed by value HOT 1
- not going inside custom resolver if absolute path is same but realtive path is different
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-schema-ref-parser.