@versionzero/schema / SchemaResolver
Class: SchemaResolver
Defined in: src/schema-resolver.js:60
The SchemaResolver uses its internal registries of named schemas and value processor keywords to convert Schemas containing unresolved references into resolved Schemas that are fully self-contained.
Methods
registerSchema()
registerSchema(
name,schema):SchemaResolver
Defined in: src/schema-resolver.js:85
add a schema to the registry
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | - |
schema | Schema | - |
Returns
SchemaResolver
getSchema()
getSchema(
name):Schema
Defined in: src/schema-resolver.js:99
return the registered schema with a given name
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | - |
Returns
hasSchema()
hasSchema(
name):boolean
Defined in: src/schema-resolver.js:113
return true if there exists a registered schema with a given name
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | - |
Returns
boolean
listRegisteredSchemas()
listRegisteredSchemas():
RegisteredSchemaInfo[]
Defined in: src/schema-resolver.js:122
return all registered schemas
Returns
RegisteredSchemaInfo[]
registerValueProcessorDefinition()
registerValueProcessorDefinition(
definition):SchemaResolver
Defined in: src/schema-resolver.js:131
Register a value processor definition
Parameters
| Parameter | Type | Description |
|---|---|---|
definition | ValueProcessorDefinition | - |
Returns
SchemaResolver
registerValueProcessor()
registerValueProcessor(
keyword,process,description?):SchemaResolver
Defined in: src/schema-resolver.js:165
register a named "simple" ValueProcessor
Parameters
| Parameter | Type | Description |
|---|---|---|
keyword | string | - |
process | ValueProcessorFunction | - |
description? | string | - |
Returns
SchemaResolver
registerValueProcessorBuilder()
registerValueProcessorBuilder(
keyword,build):SchemaResolver
Defined in: src/schema-resolver.js:183
register a complex ValueProcessor that needs to be built based on schema processor spec
Parameters
| Parameter | Type | Description |
|---|---|---|
keyword | string | - |
build | ValueProcessorBuilder | - |
Returns
SchemaResolver
listValueProcessorDefinitions()
listValueProcessorDefinitions():
ValueProcessorDefinition[]
Defined in: src/schema-resolver.js:198
List all registered value processors (and reserved builtins)
Returns
ValueProcessorDefinition[]
use()
use(
libraryFunction,options?):Promise<void>
Defined in: src/schema-resolver.js:225
Load a library of schemas and/or value processors.
Expects a (potentially async) library function accepting a SchemaResolver. Options passed to use
will be propagated to the library function.
The name option is used for error messages.
The sync option is used internally to enforce the core library does not get loaded asynchronously.
Parameters
| Parameter | Type | Description |
|---|---|---|
libraryFunction | (resolver, options) => void | Promise<void> | - |
options? | any | - |
Returns
Promise<void>
compileKeywordValueProcessorSpec()
compileKeywordValueProcessorSpec(
compiler,spec,recursive?):ValueProcessor
Defined in: src/schema-resolver.js:257
Parameters
| Parameter | Type | Description |
|---|---|---|
compiler | SchemaCompiler | - |
spec | KeywordValueProcessorSpec | - |
recursive? | boolean | - |
Returns
ValueProcessor
compileValueProcessorSpecObject()
compileValueProcessorSpecObject(
compiler,spec,recursive?):ValueProcessor
Defined in: src/schema-resolver.js:319
Convert a processor specification into an executor
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
compiler | SchemaCompiler | undefined | - |
spec | any | undefined | The processor specification |
recursive? | boolean | false | - |
Returns
ValueProcessor
compileValueProcessorSpecArray()
compileValueProcessorSpecArray(
compiler,spec,recursive?):ValueProcessor
Defined in: src/schema-resolver.js:340
Convert a processor specification into an executor
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
compiler | SchemaCompiler | undefined | - |
spec | any | undefined | The processor specification |
recursive? | boolean | false | - |
Returns
ValueProcessor
compileValueProcessorSpec()
compileValueProcessorSpec(
compiler,spec,recursive?):ValueProcessor
Defined in: src/schema-resolver.js:362
Convert a value processor specification into a value processor executor
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
compiler | SchemaCompiler | undefined | - |
spec | any | undefined | The processor specification |
recursive? | boolean | false | - |
Returns
ValueProcessor
compile()
compile(
inputSchema):CompiledSchema
Defined in: src/schema-resolver.js:452
Build a compiled schema from the schema definition.
Parameters
| Parameter | Type | Description |
|---|---|---|
inputSchema | CompiledSchema | SchemaData | Schema | - |
Returns
resolve()
resolve(
inputSchema,recursive?):CompiledSchema|Schema
Defined in: src/schema-resolver.js:470
Create a new Schema that contains the flattened hierarchy of all resolved base schemas.
This can be useful if you need to make changes to the full schema, e.g. prepending processors before the base class handlers.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
inputSchema | string | CompiledSchema | SchemaData | Schema | undefined | - |
recursive? | boolean | true | - |