Skip to content
forked from tlivings/extrefs

Resolves external refs into an object containing subschemas.

Notifications You must be signed in to change notification settings

cioplenu/extrefs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

extrefs

Resolves references in json-schema to an object containing schemas keyed by reference.

usage

import Resolver from 'extrefs';

Resolver(schema).resolve((error, schemas) => {
    //plugin into validator
});

Example:

//schema.json
{
    "type": "object",
    "properties": {
        "example": {
            "$ref": "example.json"
        }
    }
}

//example.json
{
    "type": "string"
}

Will result in an object containing:

{
    "example.json": {
        "type": "string"
    }
}

Which can then be used in conjunction with a schema validator.

For remote references (i.e. urls), resulting schemas that contain local external references (i.e just a filename) will be replaced with a fully qualified URL to the schema for proper resolution.

//schema.json
{
    "type": "object",
    "properties": {
        "example": {
            "$ref": "http://example.org/example.json"
        }
    }
}

//http://example.org/example.json
{
    "type": "object",
    "properties": {
        "more": {
            "$ref": "more.json"
        }
    }
}

//http://example.org/more.json
{
    "type": "string"
}

Will result in:

{
    "http://example.org/example.json": {
        "type": "object",
        "properties": {
            "more": {
                "$ref": "http://example.org/more.json"
            }
        }
    },
    "http://example.org/more.json": {
        "type": "string"
    }
}

resolve(schema, options) options

  • basedir - base directory to search local file references for.

About

Resolves external refs into an object containing subschemas.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%