Comments (10)
This is a valid bug; it violates the spec WRT internal links. Internal links are not necessarily JSON pointers.
$ node -e 'require("json-schema-ref-parser").dereference({"$ref": "#bar", "definitions": {"bar": {"$id": "#bar"}}}).then(s=>console.log(s))'
(node:17237) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2):
SyntaxError: Invalid $ref pointer "bar". Pointers must begin with "#/"
$ ajv -d <(echo null) -s <(echo '{"$ref": "#bar", "definitions": {"bar": {"$id": "#bar"}}}')
/dev/fd/63 valid
ajv gets it right
see also
http://json-schema.org/latest/json-schema-core.html#rfc.section.9.2 $id
"To name subschemas in a JSON Schema document, subschemas can use "$id" to give themselves a document-local identifier. This is done by setting "$id" to a URI reference consisting only of a fragment. The fragment identifier MUST begin with a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".")."
http://json-schema.org/latest/json-schema-core.html#rfc.section.9.2.1 Internal links
"Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id".
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id". This is known as "Internal referencing"."
http://json-schema.org/latest/json-schema-core.html#rfc.section.5 Fragment identifiers
"plain name fragment identifiers are reserved for referencing locally named schemas. All fragment identifiers that do not match the JSON Pointer syntax MUST be interpreted as plain name fragment identifiers."
from json-schema-ref-parser.
6.1.0 has the same bug
from json-schema-ref-parser.
I intend to support inline references in the next version of JSON Schema $Ref Parser, which I have already begun working on. 👍
In the meantime, I will implement @n1ywb's stopgap recommendation of ignoring these references.
from json-schema-ref-parser.
I just published version 3.3.1, which includes the stopgap fix that @n1ywb suggested
from json-schema-ref-parser.
Faced it today in 9.0.6 version.
from json-schema-ref-parser.
This error means that you have an invalid $ref
somewhere in your schema. Without actually seeing your schema, I can't get any more specific than that.
from json-schema-ref-parser.
as a stopgap the program could simply ignore internal refs. Not ideal but better than crashing.
from json-schema-ref-parser.
Example dereferencing local refs
_walkSchema(schema, accum) {
return _.reduce(Object.entries(schema), (a, [k, v])=>{
if (k === '$id') a.ids[v] = a.parent;
k === '$ref' && a.refs.push(a.parent);
if (v && typeof v == "object") {
let oldParent = a.parent;
a.parent = v;
let r = this._walkSchema(v, a)
a.parent = oldParent;
return r;
}
return a;
}, accum);
}
_derefLocal(schema) {
let stuff = this._walkSchema(
schema,
{parent: schema, ids: {}, refs: []}
);
stuff.refs.forEach(ref=>{
if (ref.$ref[0] === '#' && ref.$ref[1] !== '/') {
_.assign(ref, stuff.ids[ref.$ref]);
delete ref.$id;
delete ref.$ref;
}
})
console.log(stuff);
return schema;
}
from json-schema-ref-parser.
this seems to duplicate #17
from json-schema-ref-parser.
I think this might also be related to #136
from json-schema-ref-parser.
Related Issues (20)
- `Could not resolve "node-fetch"` error with sveltekit & vite HOT 2
- References to existing but null values fail as missing HOT 2
- Incorrect path resolving for absolut paths under windows HOT 5
- isExcludedPath is not a function. HOT 1
- TypeError: (0 , path_1.join) is not a function HOT 1
- merge the resolved value and the original reference HOT 3
- Browser is trying to require `fs/promises` HOT 3
- 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
- Relative references not working correctly. HOT 8
- Dereferencing time out HOT 1
- Exclude $id from dereferenced schemas HOT 2
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.