sagold / json-schema-library

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
MIT License
164 stars 19 forks source link

Clearly document how remote schemas are identified #28

Closed Carl-Foster closed 1 year ago

Carl-Foster commented 1 year ago

Our schemas are mostly defined for file-based access and we utilise the library for stitching together the schemas. We found a fair bit of hassle with the way the remote schemas were keyed when adding through addRemoteSchema.

{
    "$id": "OurCoolSchema.json"
}

{
    "$id": "ConsumerSchema.json",
    "properties": {
        "referenced": {
             "$ref": "OurCoolSchema.json"
        }
    }
}

To have this properly resolve, its needed to do draft.addRemoteSchema("ConsumerSchema.json/OurCoolSchema.json", OurCoolSchema). This isn't documented anywhere and it took quite a bit of searching to get this right. This is a common issue we have found with json-schema libraries, but a nice note about how the resolution works would be appreciated.

Carl-Foster commented 1 year ago

Note I am happy to contribute a fix for this.

sagold commented 1 year ago

Hi Carl.

Thank you for spotting issues in the README. Happy to update the usage of remote schemas. Feedback on the upcoming update is highly appreciated.

Sascha

sagold commented 1 year ago

Hi Carl,

I updated the description and examples of addRemoteSchema. I hope its becoming obvious on how to work with remote references. As said, any feedback is highly welcome.

https://github.com/sagold/json-schema-library/tree/develop#addremoteschema

Cheers, Sascha