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

Error: Unsupported $ref value: #/definitions/mongoIdentifier #5

Open
DannyBrown-xx opened this issue May 5, 2016 · 3 comments
Open

Comments

@DannyBrown-xx
Copy link

Hi,

I am using a JSON schema that passes through both http://www.jsonschemavalidator.net/ and http://jsonschemalint.com/draft4/. It uses $ref attributes which point to a defitions section inside the same JSON schema file, e.g. #/definitions/mongoIdentifier.

This fails both when I pass I pass the definitions from the schema file as a parameter

const mongooseSchema = createMongooseSchema(schema.definitions, schema);

and when I pass an empty object:

const mongooseSchema = createMongooseSchema({ }, schema);

The library says this is currently unsupported. How easy would it be to remedy, or am I just doing something incorrectly?

Thanks,
Danny

@jon49
Copy link
Owner

jon49 commented May 6, 2016

I no longer do Node.js. You are welcome to put in a pull request or take over the library. Thanks!

@iaincollins
Copy link
Collaborator

iaincollins commented Jan 5, 2017

@dannybrown Hi Danny, i realise this is ancient now but for anyone who gets here with it, I have a project that uses json-schema-to-mongoose with json-schema-ref-parser to parse schemas with references (including local definitions in the same or other files and, remote references).

The relevant code is here but you probably better off just looking at the json-schema-ref-parser docs.

The only not-easily-resolvable issue I ran into was circular references, but they are avoidable if it's your own schema and I've not found them to be terribly common in others.

@jschnaitmann
Copy link

jschnaitmann commented Feb 1, 2017

Another simple possiblity:

function extractDefinitionsAndCreateMongooseSchema(oSchema) {
    var oDefinitions = { '#': oSchema };
    
    for (let sDef in oSchema.definitions) {
        oDefinitions['#/definitions/' + sDef] = oSchema.definitions[sDef];
    }
    
    oMongooseSchema = createMongooseSchema(oDefinitions, oSchema);
}

Doesn't help with the circular references though - in this case, the reference back to the schema root using '#' leads to RangeError: Maximum call stack size exceeded.

My problem - the basic JSON Schema itself (https://github.com/json-schema-org/json-schema-spec/blob/master/schema.json) uses those references, however, I do want to store those in the database as well. Did someone get around that problem?

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

4 participants