Closed TimBo93 closed 2 years ago
We were able to solve the issue by calling
const jsonSchema = new JsonSchemaLibrary();
jsonSchema.setSchema(schema);
return getTemplate(jsonSchema, data);
What I have reported may not a bug, but more likely a misunderstanding in the API. I was confused that it only fails when using $ref.
Hi @TimBo93 thank you for the feedback.
For resolution of ids, scopes and references a json-schema has to be compiled before being able to resolve $refs. This is probably not done in the case of getTemplate
. You can compile a schema yourself using
import { compileSchema } from "json-schema-library";
const myCompiledSchema = compileSchema(mySchema);
setting the rootschema (which contains the definitions/defs) in the constructor or via setSchema
will do this automatically, e.g.
const jsonSchema = new JsonSchemaLibrary(mySchema);
or
const jsonSchema = new JsonSchemaLibrary();
jsonSchema.setSchema(mySchema);
I will update the documentation about this, add the compile command to getTemplate
and think about possible api improvements.
Cheers, Sascha
Documentation has been updated and latest api changes should prevent some of thise errors.
Hi,
thank you for your library! We are using your library in order to create default-templates based on a schema.
At this point we are facing an issue:
regarding: https://www.jsonschemavalidator.net/ the schema itself should be valid.
getTemplate
throws the following exception:TypeError: Cannot read properties of undefined (reading 'getRef')
Are we missing something?
Kind regards Tim