question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference local files, by schema/property id

See original GitHub issue

I’m currently using the ajv lib and some custom logic to dereference my schemas, and then I found this lib which will probably do a better job. Is there a way to add schemas so this lib is aware of them? My JSON schemas reference by id, so for example in ajv I’m loading all my schemas schemas.forEach(schema => ajv.addSchema(schema)) and then trying to parse the $refs. Is there something similar I can do for this lib? Or is the example in the docs the only way "$ref": "schemas/people/Bruce-Wayne.json"?

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Relequestualcommented, Sep 27, 2018

@5amfung It looks like custom resolvers are supported: https://github.com/James-Messinger/json-schema-ref-parser/blob/master/docs/plugins/resolvers.md

If you’re willing to write a resolver plugin which replaces the HTTP resolver, please do, and make a PR for it.

An issue with that solution is that schemas which use a mixture of addressable and non addressable URLs would run into problem. Maybe you could add provision in your resolver to only resolve specific domains, otherwise pass through the URL to the standard resolver.

2reactions
5amfungcommented, Sep 26, 2018

Like @brettstack, I have a set of schema files that are not accessible through http but only accessible from a file directory. These schema are unfortunately referenced by their $id. I know $id is not supported as explained above. But is there a way for me to provide the schema instead of the parser to go downloading it through http? Perhaps a custom parser?

@James-Messinger Any pointer would be very much appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Referencing a local relative file in a JSON Schema?
Given where your file is located, use: final JsonSchema schema = factory.getJsonSchema("resource:/json/schema/MySchema.schema.json");.
Read more >
How to reference a local JSON schema - iancarpenter.dev
One sentence summary This post will show you how to use a locally stored JSON schema to validate a JSON document.
Read more >
Combining schemas - Ajv JSON schema validator
Combining schemas with $ref. You can structure your validation logic across multiple schema files and have schemas reference each other using $ref keyword....
Read more >
Using $ref - Swagger
components: schemas: User: properties: id: type: integer; name: type: string ... Local Reference – $ref: '#/definitions/myElement' # means go to the root of ......
Read more >
Managing references ($ref) - JSON Schema
Download static property is a function that takes a string (the $id URI) and returns the serialized JSON Schema content. This method is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found