Reference local files, by schema/property id
See original GitHub issueI’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:
- Created 7 years ago
- Reactions:5
- Comments:12 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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.