简体   繁体   中英

Folder Reference for JSON Schema

I am trying to refer to schema located in a sub folder with $ref, I wanted to put as optional a couple of other schema files into my root schema file. I have seen about cross file reference and in file referencing with $ref, but wanted to check if an entire schema file/files can be referenced by folder. ie. for eg:

./subfolder/{...}.json

contains a list of schema files and in my root schema file i would like to reference them like

"$ref": "./subfolder/"

I am assuming, I could expand a schema file infinitely using a format like this. Thank for your answer and time.

It's better described as cross- resource referencing. JSON Schema has no notion of files or folders or file systems.

Instead, it does have the notion of URIs and URI resolution.

The approach you should take is to give each schema resource (contained in a JSON file), a full URI using $id . Then use full (or relative) references. You can use relative references if your URIs all use the same first parts (protocol and domain for example).

The implementation you're using should allow you to load in multiple schemas OR provide a means to resolve references using a user-defined function.

The usual approach is to load in all schemas, and then allow the URI references to resolve based on an index of $id .

Once you've loaded a schema into an implementation, it won't know the file it originally came from (if any), and can only rely on the URIs provided in the schema itself. Your schemas may define URIs as if they were available at different paths, but ultimately you COULD store them all in the same folder regardless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM