APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
957 stars 228 forks source link

Using $id as a base url for $ref #218

Closed ninobc closed 3 years ago

ninobc commented 3 years ago

Hi guys.

So just to give a brief explanation of what I'm trying to achieve. I'm trying to figure out how to properly read remote schemas that are modular and referencing each other though the $ref's. For example:

// Schema-A


{
    "$schema": "http://json-schema.org/draft-07/schema#",  
    "$id": "http://example.com/schemas/schema-a.json",  
    "title": "Schema A",  
    "type": "object",  
    "properties": {  
      "object": {  
        "$ref": "schema-b.json"
      },  
    }  
}

// Schema-B resides in the same directory but in another file

Now let's say both of these schemas are being hosted online and are reachable via the urls below:

Would there be a way to dereference Schema-A and have Schema-B referenced through the url above by using $id? If not, what's the recommended way of referencing externally hosted schemas?

Your support would be greatly appreciated!